/* Meant to be used only in development mode. */ Object.defineProperty( Number.prototype, 'times', { configurable: false, enumerable: false, writable: false, value: function (fn, init=0) { var cb, acc = [init]; if (typeof fn === 'function') { cb = fn; } else if (typeof fn === 'number') { cb = () => fn; } else if (typeof fn === 'string') { cb = () => fn; acc[0] = ''; } else if (typeof fn === 'undefined') { cb = (i) => i; } for (let i = 0; i < this; i++) { let r = cb(i, acc[0]); acc[0] += r; acc.push(r); } acc.push([acc.shift()]); return acc; }, } ); // examples: var eleven = 11; eleven.times(); // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, [ 55 ] ] eleven.times(8); // [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, [ 88 ] ] eleven.times('8'); // [ '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', [ '88888888888' ] ] eleven.times((_, a) => a, 1); // [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, [ 2048 ] ] eleven.times((i) => i + 8, 8); // [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, [ 151 ] ]