Last active
November 1, 2019 14:55
-
-
Save ourmaninamsterdam/401e5d5b31b548123b42a37976b4edf4 to your computer and use it in GitHub Desktop.
Generate incremented numbers
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
const generateIncrementedNumbersList = (min, max, increment, includeMin) => { | |
const items = []; | |
let incrementor = Math.max(min, increment); | |
if (includeMin) { | |
items.push(min); | |
} | |
while (incrementor <= max) { | |
items.push(incrementor); | |
incrementor += increment; | |
} | |
return items; | |
} | |
console.log(generateIncrementedNumbersList(500, 10000, 1000, true)); | |
// [ 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 ] | |
console.log(generateIncrementedNumbersList(1, 100, 10, true)); | |
// [ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment