Last active
July 16, 2024 14:21
-
-
Save jonrandy/a6a3c27b2ad9e6ec077ecce6ee746d06 to your computer and use it in GitHub Desktop.
Range
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
const to = Symbol('number to') | |
// Number.prototype[to] = function to(end) { | |
// let [start, tend, rev] = (this>end) ? [end, this, true] : [this, end, false], arr = [] | |
// for (let i=start; i<=tend; i++) arr.push(i) | |
// return rev ? arr.sort(_=>1) : arr | |
// } | |
Number.prototype[to] = function to(end, {step}={step:this<=end?1:-1}) { | |
let arr = [], i, d = end>this | |
for (i=+this;d?(i<=end):(i>=end);i+=step) arr.push(i) | |
return arr | |
} | |
console.log(1[to](11)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment