Skip to content

Instantly share code, notes, and snippets.

@zhmushan
Created December 31, 2021 06:51
Show Gist options
  • Save zhmushan/9bb0bce203fe1dbd594aa320219761c7 to your computer and use it in GitHub Desktop.
Save zhmushan/9bb0bce203fe1dbd594aa320219761c7 to your computer and use it in GitHub Desktop.
/**
* @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