const myBind = (boundTargetFunction, boundThis, boundArguments) => { return (...newBoundArguments) => { const iterator = newBoundArguments.values(); let updatedArr = []; boundArguments.forEach((element, index, thisArr) => { element === undefined ? updatedArr.push(iterator.next().value) : updatedArr.push(thisArr[index]); }); return boundTargetFunction.apply(boundThis, updatedArr); } } let pow5 = myBind(Math.pow, Math, [undefined, 5]); let cube = myBind(Math.pow, Math, [undefined, 3]); console.log(pow5(2)); //32 console.log(cube(3)); //27 let chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9]) console.log(chessMin(-1,-5,3,15)); //-5 let zeroPrompt = myBind(prompt, window, [undefined, "0"]); let someNumber = zeroPrompt("Введите число"); // вызывает prompt("Введите число","0") let joinStr = myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') console.log(joinStr) // abcdef