Sobes.tech
Middle

/** * Implementujte metódu times pre číselného objektu. * Funkcia by mala prijať callback a volať ho * stanovený počet krát s indexom aktuálnej iterácie. */ Number.prototype.times = function (callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } } // Príklady console.clear(); (3).times(console.log) // 0 // 1 // 2

sobes.tech AI

Odpoveď 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