Created
June 20, 2018 04:41
-
-
Save basekays/f1f0a8790cf45f9f48701da4f4eb0aca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * @param {number} n | |
| * @return {string} | |
| **/ | |
| var countAndSay = function(number) { | |
| var string = '1'; | |
| for (var i = 1; i < number; i++) { | |
| var stringToArray = string.split(''); | |
| var counter = 1; | |
| string = ''; | |
| for (var j = 0; j < stringToArray.length; j++) { | |
| if (stringToArray[j] !== stringToArray[j+1]) { | |
| string += counter + stringToArray[j]; | |
| } else { | |
| counter++; | |
| } | |
| } | |
| } | |
| return string; | |
| } | |
| countAndSay(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment