Last active
March 10, 2017 13:57
-
-
Save MasatoraSakikoyama/cd208557d8c427618d22ae09ae0ddc03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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