JavaScript 高阶函数
一、概念
function add(x, y, f) {
return f(x) + f(y);
}
var result = add(-5, 9, Math.abs)
console.log(result) // output: 14二、map
'use strict';
function pow(x) {
return x * x;
}
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var results = arr.map(pow); // output: [1, 4, 9, 16, 25, 36, 49, 64, 81]
console.log(results);三、reduce
3.1 求和
3.2 求积
3.3 字符串转数字
3.4 规范英文名称
3.5 字符串转整数
三、参考资料
最后更新于