Skip to content

Instantly share code, notes, and snippets.

@horiuchie
Created December 11, 2019 08:42
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 horiuchie/c7c5d43b8d0330fe039b8e4376f50589 to your computer and use it in GitHub Desktop.
Save horiuchie/c7c5d43b8d0330fe039b8e4376f50589 to your computer and use it in GitHub Desktop.
Return a list of numbers [from, to] with step.
const rangeWithStep = (from, to, step=1) => R.map(
i => from + i * step,
R.range(0, 1 + Math.floor((to - from) / step))
);
// Usage
console.log( rangeWithStep(1, 10, 2) ); // [1,3,5,7,9]
console.log( rangeWithStep(53, 92, 11) ); // [53,64,75,86]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment