Skip to content

Instantly share code, notes, and snippets.

@lcarsos
Created November 21, 2017 23:11
Show Gist options
  • Save lcarsos/42d5e40ea4f579509fc49d6fbd7cf8f3 to your computer and use it in GitHub Desktop.
Save lcarsos/42d5e40ea4f579509fc49d6fbd7cf8f3 to your computer and use it in GitHub Desktop.
Two range calculating functions using idiomatic ES6
export const stepout = (min, max, step = 1) => (
Array( Math.floor((max - min) / step) ).fill().map( ( _, i ) => min + (i * step) )
);
export const linspace = (min, max, n = 100) => {
const step = (max - min) / (n - 1);
return Array( n ).fill().map( ( _, i ) => min + (i * step) );
};
export default stepout;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment