Skip to content

Instantly share code, notes, and snippets.

@rocka
Last active June 5, 2017 04:29
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 rocka/a7bf9131f2bab84194f489924b4c3aa3 to your computer and use it in GitHub Desktop.
Save rocka/a7bf9131f2bab84194f489924b4c3aa3 to your computer and use it in GitHub Desktop.
create arithmetic sequence
Array.range = function () {
let realMin, realMax, step, arr = [];
if (arguments.length >= 3) {
realMin = arguments[0]; realMax = arguments[1]; step = arguments[2];
} else if (arguments.length === 2) {
realMin = arguments[0]; realMax = arguments[1]; step = 1;
} else if (arguments.length === 1) {
realMin = 0; realMax = arguments[0]; step = 1;
} else return arr;
const total = Math.floor((realMax - realMin) / step);
for (let i = 0; i < total; i++) {
arr[i] = realMin + i * step;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment