Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created March 10, 2016 15:19
Show Gist options
  • Save jooyunghan/2550c2841996bb03f01d to your computer and use it in GitHub Desktop.
Save jooyunghan/2550c2841996bb03f01d to your computer and use it in GitHub Desktop.
Print look-and-say sequence using Regex/Generator
const ant = function *(s = "1") {
yield s;
yield* ant(s.replace(/(.)\1?\1?/g, g => g.length + g[0]));
}
for (var i=0, a = ant(); i++<10; ) {
console.log(a.next().value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment