Middle
/** * Implementujte metodu times pro číselný objekt. * Funkce by měla přijmout callback a volat jej * stanovený početkrát s indexem aktuální iterace. */ Number.prototype.times = function (callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } } // Příklady console.clear(); (3).times(console.log) // 0 // 1 // 2
sobes.tech AI
Odpověď od 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