Middle
/** * Implementirajte metodu times za numerički objekat. * Funkcija treba da prihvati callback i da ga pozove * određen broj puta sa indeksom trenutne iteracije. */ Number.prototype.times = function (callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } } // Primeri console.clear(); (3).times(console.log) // 0 // 1 // 2
sobes.tech АИ
Одговор од АИ
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