Skip to content

Instantly share code, notes, and snippets.

@MasatoraSakikoyama
Last active March 10, 2017 13:57
Show Gist options
  • Save MasatoraSakikoyama/cd208557d8c427618d22ae09ae0ddc03 to your computer and use it in GitHub Desktop.
Save MasatoraSakikoyama/cd208557d8c427618d22ae09ae0ddc03 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;
for (let i = 0; i < length; i++, start+=step) {
yield start;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment