Ad

(Functional version with no loops)

Code
Diff
  • Number.prototype.times = function(f) { 
      const n = this.valueOf()
      const g = (_, i) => f(i)
      return [...Array(n)].map(g) 
    }
    
    • Number.prototype.times = function (f) {
    • for (let i = 0; i < this; i++) f(i);
    • }
    • Number.prototype.times = function(f) {
    • const n = this.valueOf()
    • const g = (_, i) => f(i)
    • return [...Array(n)].map(g)
    • }