jiaqiu2003's recent timeline updates
jiaqiu2003

jiaqiu2003

V2EX member #163861, joined on 2016-03-18 12:24:00 +08:00
jiaqiu2003's recent replies
@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'
May 27, 2020
Replied to a topic by fensou 生活 你有用钱解决不了的烦心事吗?
有,爱上一个不爱我的人。
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   837 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 20:49 · PVG 04:49 · LAX 13:49 · JFK 16:49
♥ Do have faith in what you're doing.