利用reduce()求积
reduce()
'use strict'; function product(arr) { return arr.reduce((x,y)=>{return x*y}) } console.log(product([1, 2, 3, 4]))
string2int()
'use strict'; function string2int(s) { let a = (s.split('')).map(x=>x*1) return a.reduce(function (x, y) { return x * 10 + y; }); }
英文首字母大写
'use strict'; function normalize(arr) { let a; return arr.map(x=>{ a = (x.split('')).map(x=>x.toLowerCase()) a[0] = a[0].toUpperCase() return a.reduce((x,y)=>x+y) }) }
改错
'use strict'; var arr = ['1', '2', '3']; var r; r = arr.map(x=>parseInt(x)); console.log(r);
Sign in to make a reply
rainux
利用
reduce()
求积string2int()
英文首字母大写
改错