Skip to content

Instantly share code, notes, and snippets.

View leomastoras's full-sized avatar
🏠
Working from home

Leo leomastoras

🏠
Working from home
View GitHub Profile
@getify
getify / number-prototype-iterator.js
Created January 25, 2017 23:52
Make JavaScript Great Again
Object.defineProperty(Number.prototype,Symbol.iterator,{
*value({ start = 0, step = 1 } = {}) {
var inc = this > 0 ? step : -step;
for (let i = start; Math.abs(i) <= Math.abs(this); i += inc) {
yield i;
}
},
enumerable: false,
writable: true,
configurable: true