Created
December 31, 2021 06:51
-
-
Save zhmushan/9bb0bce203fe1dbd594aa320219761c7 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
/** | |
* @template {number} T | |
* @param {T} start | |
* @param {T} end | |
* @param {T | (old: T) => T} increase | |
* @returns {T[]} | |
*/ | |
export default function range(start, end, increase = 1) { | |
const increaser = typeof increase === 'function' | |
? increase | |
: old => old + increase; | |
const ret = []; | |
for (let i = start; i < end; i = increaser(i)) { | |
ret.push(i); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment