Skip to content

Instantly share code, notes, and snippets.

@yangjunjun
Last active December 26, 2015 10:09
Show Gist options
  • Save yangjunjun/7134589 to your computer and use it in GitHub Desktop.
Save yangjunjun/7134589 to your computer and use it in GitHub Desktop.
look and say
/**
* look and say
*
* Reference:
* 1.https://github.com/bkarak/fuzzer-fat-fingers/blob/master/src/tasks/LookAndSay/LookAndSay.js
* 2.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
*/
function lookandsay(str) {
return str.replace(/(.)\1*/g, function(seq, p1){return seq.length.toString() + p1})
}
var num = "1";
for (var i = 10; i > 0; i--) {
console.log(num);
num = lookandsay(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment