Code Monkey home page Code Monkey logo

exercise2's People

Contributors

miniflycn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

exercise2's Issues

大数相加问题以及jsPerf性能测试报告

https://jsperf.com/calc-compare-twice/
这一份是对比了两次while循环的substr,发现我的单次while循环基本上比它慢一点

https://jsperf.com/calc-compare-bit/
这一份是对比按位操作的,基本上单次循环的substr比它快

我的方法基本上处于两者之间,为保证测试结果测试用例参考的是issue中的,想请问一下老师,我的写法是否有改进的地方
ps:不知道为何我的jsperf无法添加snippet,没有那个按钮=。=

大数相加网上找的一个很简洁的案例,个人觉得写得很好

给大家分享一个我百度出来的一个范例,我看的不是很懂,但是觉得写得真心简洁而且好,已经在测试案例中测试通过了!!!

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+/,'');
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.