Last active
December 26, 2015 10:09
-
-
Save yangjunjun/7134589 to your computer and use it in GitHub Desktop.
look and say
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
/** | |
* 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