Skip to content

Instantly share code, notes, and snippets.

@PuercoPop
Created March 18, 2014 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PuercoPop/9611220 to your computer and use it in GitHub Desktop.
Save PuercoPop/9611220 to your computer and use it in GitHub Desktop.
Why?
function repeat(x,n) { var a=[]; for (;n>0;n--) a.push(x); return a; }
// returns an array of the first `n` natural numbers
function range(n) {
return repeat('10', n+2).map(parseInt).slice(2).map(function(x) {
return x-2;
});
}
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, NaN, NaN, NaN, NaN, NaN]
function repeat(x,n) { var a=[]; for (;n>0;n--) a.push(x); return a; }
// returns an array of the first `n` natural numbers
function range(n) {
return repeat('10', n+2).map(function(num) {return parseInt(num, 10);}).slice(2).map(function(x) {
return x-2;
});
}
[8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment