Skip to content

Instantly share code, notes, and snippets.

@eknowles
Last active April 8, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eknowles/f081c61114ec4a5c99f6cc77cd23b6f5 to your computer and use it in GitHub Desktop.
Save eknowles/f081c61114ec4a5c99f6cc77cd23b6f5 to your computer and use it in GitHub Desktop.
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