Created
April 4, 2018 09:34
-
-
Save hrdtbs/b27e65a7f8ea0ffc57b2bc367753a92d to your computer and use it in GitHub Desktop.
like python range
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
const range = (from, to, step) => { | |
if (from === undefined) return []; | |
if (to === undefined) return [...Array(from).keys()]; | |
if (step === undefined) | |
return [...Array(to - from).keys()].map(x => x + from); | |
return [...Array(Math.ceil((to - from) / step)).keys()].map( | |
x => x * step + from | |
); | |
}; | |
export default range; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment