Created
September 22, 2014 13:41
-
-
Save todashuta/eb9326d470047849efe5 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
| ;(function() { | |
| var collatz = function(i) { | |
| var list = [i]; | |
| while (list.slice(-1) > 1) { | |
| var n = list.slice(-1); | |
| if (n % 2 === 0) { | |
| n = n / 2; | |
| } else { | |
| n = 3 * n + 1; | |
| } | |
| list.push(n); | |
| } | |
| return list; | |
| } | |
| console.log(collatz(3)); | |
| }()); |
Author
todashuta
commented
Sep 22, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment