Skip to content

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

@asd2766

Description

@asd2766

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions