title


题目目录

方法一是用toLocalString方法

另一种就是逐个遍历最后把小数点后的数字拼上

函数柯里化

实现add(1)(2)(3)

  1. 暴力版
1
2
3
4
5
6
7
function add(a){
return function (b){
return function (c){
return a+b+c;
}
}
}
  1. 非暴力版

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function add(a) {
    let sum = a
    const inner = function (b) {
    console.log(sum);
    sum += b
    return inner;
    }
    inner.toString = function () {
    return sum;
    }
    return inner;
    }
    add(1)(2)(3).toString();
  2. 解决多个参数问题

  3. 解决必须用toString的缺点,这次必须在末尾多个括号

最大数字展示

大数相加

1
2
3
4
5
6
7
8
9
10
11
12
function bsum(a,b){
var aa=(a+'').split('');
var bb=(b+'').split('');
var temp=0;
let res='';
while(aa.length>0||bb.length>0||temp){
let now=~~aa.pop()+~~bb.pop()+temp;
res=now+res;
temp=parseInt(now/10);
}
return res;
}

树形结构

循环点亮红绿黄


Author: pkq
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source pkq !
  TOC