Sobes.tech
Middle

/** * Implementare il metodo times per un oggetto numerico. * La funzione deve accettare un callback e chiamarlo * un numero specificato di volte con l'indice dell'iterazione corrente. */ Number.prototype.times = function (callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } } // Esempi console.clear(); (3).times(console.log) // 0 // 1 // 2

sobes.tech AI

Risposta dell'AI

javascript Number.prototype.times = function(callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } };

// Пример использования (3).times(console.log); // Выведет: // 0 // 1 // 2