在 JavaScript 中对数组元素进行倍增的 Currified 函数
问题
我们需要编写一个JavaScript函数,该函数接受一个数组并返回另一个函数,该函数又接受一个数字,该数字返回一个新数组,该数组是第一个函数的输入数组的相应元素与提供给第一个函数的数字的乘积。第二个功能。
示例
以下是代码-
const arr = [2, 5, 2, 7, 8, 4]; const num = 4; const produceWith = (arr = []) => (num) => { const res = arr.map(el => { return el * num; }); return res; }; console.log(produceWith(arr)(num));输出结果
以下是控制台输出-
[ 8, 20, 8, 28, 32, 16 ]