//Пример:
function sayHello() {
return 'Hello';
}
function limit(fn, times) {
return function(...args) {
if (
typeof times !== 'number' ||
!Number.isInteger(times) ||
times === 0 ||
times < 0 ||
typeof fn !== 'function'
) {
return undefined;
} else {
times--;
return fn(...args);
}
};
}
//const limitedSayHello = limit(sayHello, 1);
//const limitedSayHello = limit(sayHello, 2);
//console.log(limitedSayHello()); // "Hello"
//console.log(limitedSayHello()); // "Hello"
//console.log(limitedSayHello()); // undefined
const t = limit(sayHello, 2);
console.log(t()); // что вернёт теперь?
const t2 = limit(sayHello);
console.log(t2()); // что вернёт?
Click Run to execute JavaScript.
Code runs in an isolated environment.
Code runs in an isolated environment.