Created
March 16, 2011 00:58
-
-
Save yuanchuan/871830 to your computer and use it in GitHub Desktop.
rinting 1 to 1000 without loop or conditionals
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
//Printing 1 to 1000 without loop or conditionals | |
//http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals/4583502#4583502 | |
// using replace | |
(function(max){ | |
new Array(max + 1).join(' ').replace(/\s/g, function(c, i){ | |
console.log(i + 1); | |
}) | |
})(1000) | |
// using recursion (so ineffective) | |
(function print(i, max) { | |
console.log(++i); | |
({0 : print, 1 : function(){}})[(i / max) >> 0](i, max); | |
})(0, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment