Last active
December 15, 2015 02:09
-
-
Save kpuputti/5185688 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
// range0(n) -> [0, ... , (n - 1)] | |
function range0(n) { | |
return Array.apply(null, Array(n)).map(function (val, i) { | |
return i; | |
}); | |
} | |
// range(end) -> [0, ... , (end - 1)] | |
// or | |
// range(start, end) -> [start, ... , (end - 1)] | |
function range() { | |
if (arguments.length === 1) { | |
return range0(arguments[0]); | |
} else if (arguments.length === 2) { | |
return range0(arguments[1]).slice(arguments[0]); | |
} else { | |
throw new Error('Bad arguments.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment