Middle
/* * Implement the times method for a numeric object. * The function should accept a callback and call it * a specified number of times with the current iteration index. */ Number.prototype.times = function (args) { const n = Number(this); } // Examples console.clear(); (3).times(console.log) // 0 // 1 // 2
sobes.tech AI
Answer from AI
javascript Number.prototype.times = function(callback) { const n = Number(this); for (let i = 0; i < n; i++) { callback(i); } };
// Example usage (3).times(console.log); // Will output: // 0 // 1 // 2