Skip to content

Instantly share code, notes, and snippets.

@pluma
Created November 13, 2015 10:53
Show Gist options
  • Save pluma/16823e5299cb3030410d to your computer and use it in GitHub Desktop.
Save pluma/16823e5299cb3030410d to your computer and use it in GitHub Desktop.
const range1 = n => Array.from(Array(n).keys());
const range2 = (off, n) => Array.from(Array(n - off).keys()).map(i => i + off);
const range3 = (off, step, n) => Array.from(Array(Math.ceil((n - off) / step)).keys()).map(i => i * step + off);
const range = (...args) => args.length === 1 ? range1(...args) : args.length === 2 ? range2(...args) : range3(...args);
const repeat = (x, n) => Array.from(Array(n)).map(() => x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment