Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Created April 4, 2018 09:34
Show Gist options
  • Save hrdtbs/b27e65a7f8ea0ffc57b2bc367753a92d to your computer and use it in GitHub Desktop.
Save hrdtbs/b27e65a7f8ea0ffc57b2bc367753a92d to your computer and use it in GitHub Desktop.
like python range
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