文章 评论 浏览 28
在30-seconds-of-code看到一个这个题的变形,分享一下let unary = fn => val => fn(val) let parse = unary(parseInt) console.log(['1.1', '2', '0.3'].map(parse))
在30-seconds-of-code看到一个这个题的变形,分享一下
let unary = fn => val => fn(val) let parse = unary(parseInt) console.log(['1.1', '2', '0.3'].map(parse))
这种方法绕过了parseInt的第二个参数,实际执行如下:console.log(['1.1', '2', '0.3'].map( item => {return parseInt(item)}))花里胡哨的。
function out(value){ if(value.length===0) return ''; value = Array.isArray(value)?value:value.toString().split(''); return value.pop() + out(value); }
文章 0 评论 0
接受
这种方法绕过了parseInt的第二个参数,实际执行如下:
console.log(['1.1', '2', '0.3'].map( item => {
return parseInt(item)
}))
花里胡哨的。
第 2 题:['1', '2', '3'].map(parseInt) what & why ?