题目描述

We want to create a function that will add numbers together when called in succession.

add(1)(2);
// returns 3


We also want to be able to continue to add numbers to our chain.

add(1)(2)(3); // 6
add(1)(2)(3)(4); // 10
add(1)(2)(3)(4)(5); // 15


and so on.

A single call should return the number passed in.

add(1); // 1


We should be able to store the returned values and reuse them.

var addTwo = add(2);
addTwo; // 2
addTwo + 5; // 7
addTwo(3); // 5
addTwo(3)(5); // 10


We can assume any number being passed in will be valid whole number.

Example

Test.expect(add(1) == 1);
Test.expect(add(1)(2) == 3);
Test.expect(add(1)(2)(3) == 6);


我完成的代码

function add (num) {// 1
var count = num;
var sum = function(num2){ // 2,3......
count += num2;
return sum
}
sum.valueOf = function(){
return count  // return both a function and a value
}
return sum
}


我的思路

sum.valueOf = function(){
return count  // return both a function and a value
}


我的难点

09-26

09-16 193

09-17 121

05-20 20

08-29 164

03-06 59

03-17 129

03-08 110

10-12 72

09-07 61

08-12 231

09-05 52

03-30 157

02-09 224

03-02 1万+

05-20 23

05-14 34

01-13

09-08 87

09-08 54

09-07 58

03-06 89

04-08 600

08-29 180

05-16 27

08-29 182

06-18 119

08-29 225

09-07 71

03-05 60

07-30 454

07-31 597

08-29 197

12-29 184

08-29 105

08-30 143

02-23 4万+

02-13 179

06-20 154

03-01 13万+

03-02 1万+

05-21 34

04-02 40

09-14 250

02-27 8万+

06-28 100

01-13 30

09-05 47

02-27 4万+

05-19 21

04-01 40

09-05 65

03-05 6万+

03-04 14万+

04-14 59万+

03-08 7万+

03-08 5万+

03-13 15万+

02-19 18万+

03-06 3218

03-08 2万+

04-25 7万+

03-10 13万+

03-10 19万+

03-12 11万+

03-13 11万+

03-16 2526

03-18 1万+

03-19 8万+

03-19 4万+

03-20 1万+

03-22 5043

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 5万+

无代码时代来临，程序员如何保住饭碗？

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客