- Fork 代码仓库并拉到本地
- 安装依赖
npm install
- 启动测试
npm run test
- 打开
./lib/add.js
修改代码跑通测试用例 - 提交github,尝试接入Github Actions
课程练习 2:实现一个大数相加需求
npm install
npm run test
./lib/add.js
修改代码跑通测试用例给大家分享一个我百度出来的一个范例,我看的不是很懂,但是觉得写得真心简洁而且好,已经在测试案例中测试通过了!!!
function sumStrings(a,b){
var res='', c=0;
a = a.split('');
b = b.split('');
while (a.length || b.length || c){
c += ~~a.pop() + ~~b.pop();
res = c % 10 + res;
c = c>9;
}
return res.replace(/^0+/,'');
}
https://jsperf.com/calc-compare-twice/
这一份是对比了两次while循环的substr,发现我的单次while循环基本上比它慢一点
https://jsperf.com/calc-compare-bit/
这一份是对比按位操作的,基本上单次循环的substr比它快
我的方法基本上处于两者之间,为保证测试结果测试用例参考的是issue中的,想请问一下老师,我的写法是否有改进的地方
ps:不知道为何我的jsperf无法添加snippet,没有那个按钮=。=
大数相加平时也没多考虑,一时不知道如何下手,搜索到一篇比较好的文章:
http://www.plqblog.com/views/article.php?id=29
javascript一系列的上限下限(文章中的图,挺不错的)
或者可以参考第三方比较成熟的类库bignumber.js,学习下实现思路及边界处理等。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.