Last active
April 8, 2020 13:54
-
-
Save eknowles/f081c61114ec4a5c99f6cc77cd23b6f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function say(str, iterations) { | |
let total = str; | |
for (let i = 0; i < iterations; i++) { | |
let count = 0; | |
let output = ''; | |
for (let i = 0; i <= total.length; i++) { | |
if (i === 0 || total[i] === total[i - 1]) { | |
count = count + 1; | |
} else { | |
output = `${output}${count}${total[i - 1]}`; | |
} | |
} | |
total = output; | |
} | |
return total; | |
} | |
console.log( | |
say('1', 1), | |
say('1', 2), | |
say('1', 3), | |
say('1', 4), | |
say('1', 5) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment