Last active
June 5, 2017 04:29
-
-
Save rocka/a7bf9131f2bab84194f489924b4c3aa3 to your computer and use it in GitHub Desktop.
create arithmetic sequence
This file contains 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 () { | |
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