jiaqiu2003 最近的时间轴更新
jiaqiu2003

jiaqiu2003

V2EX 第 163861 号会员,加入于 2016-03-18 12:24:00 +08:00
jiaqiu2003 最近回复了
@phpfpm 无限进位。。。又 miss 掉一个点。放弃
@phpfpm 麻烦看下这个。进位的那个算是抄袭吧。。。实在没想到好的
function add(a, b) {
if (a.length > b.length) {
return add(b, a);
}
const prefix = b.substring(0, b.length - a.length - 1);
return prefix + `0${a}`.split('').reverse().reduce((acc, s, idx) => {
const carray = acc.length - idx;
return s * 1 + b[b.length - idx - 1] * 1 + carray + acc.substring(carray);
}, '');
}
@phpfpm 感谢~
我再想一个
function add(str1, str2) {
const getNum = str => str.split('').reverse().reduce((acc, s, idx) => acc + (s * 10 ** idx), 0);
return getNum(str1) + getNum(str2) + '';
}
add('123', '21'); // Print '144'
2020-05-27 11:05:19 +08:00
回复了 fensou 创建的主题 生活 你有用钱解决不了的烦心事吗?
有,爱上一个不爱我的人。
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1260 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 17:46 · PVG 01:46 · LAX 10:46 · JFK 13:46
Developed with CodeLauncher
♥ Do have faith in what you're doing.