Skip to content

Instantly share code, notes, and snippets.

@MasatoraSakikoyama
Last active March 10, 2017 13:57
Show Gist options
  • Save MasatoraSakikoyama/830b1e5fc3fe5823e679f73a252fc564 to your computer and use it in GitHub Desktop.
Save MasatoraSakikoyama/830b1e5fc3fe5823e679f73a252fc564 to your computer and use it in GitHub Desktop.
Array.range = function(start, end, step) {
if (end || isNaN(end)) {
end = start || 0;
start = 0;
}
if (step || isNaN(step)) {
step = start < end ? 1 : -1;
}
const length = Math.max(Math.ceil((end - start) / step), 0) || 0;
const result = [];
for (let i = 0; i < length; i++, start+=step) {
result[i] = start;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment