[[3,2,1].reduce(Math.pow),[].reduce(Math.pow)];
结果图
解析:
array.reduce(fn,initialValue);
fn(total,currentValue,currentIndex,arr);
reduce:
fn必选,initialValue为初始值,若不传则默认数组的第一个值。
fn:
前两项必选,第一项为返回值或者是初始值,currentValue为当前传入的值,第三项为当前项索引,第四项为元素所属数组。
Math.pow(x,y):
x为底数,y为指数。
[3,2,1].reduce(Math.pow):
[x1,x2,x3].reduce(Math.pow):相当于Math.pow(Math.pow(x1,x2),x3);
Math.pow(3,2):9=>Math.pow(9,1):9 所以结果为9
[].reduce(Math.pow):
reduce前的数组不得为空,若为空将无法取到reduce的初始值,所以会出现上图所示的报错。