function str2int (s){
return Array.prototype.map.call(s, x => x - 0).reduce((x,y) => x * 10 + y)
}
function str2int2 (s) {
return s.split().reduce((x,y) => x * 10 + y/1,0)
}
function str2int3 (s) {
return [].reduce.call(s,(x,y) => x * 10 + y/1,0)
}
console.log(str2int("10"));
console.log(str2int2("100"));
console.log(str2int3("10"));
不使用Number或parseInt将字符串转换为数字
最新推荐文章于 2022-04-07 21:21:43 发布