Merge pull request #1956 from Logan-Schelly/testcases/function-object-5

Testcases/function object 5
This commit is contained in:
Ilya Kantor 2020-06-16 09:14:54 +03:00 committed by GitHub
commit 0ef2dd3ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,15 @@
function sum(a) {
let currentSum = a;
function f(b) {
currentSum += b;
return f;
}
f.toString = function() {
return currentSum;
};
return f;
}

View file

@ -0,0 +1,12 @@
function sum(a){
// Your code goes here.
}
/*
sum(1)(2) == 3; // 1 + 2
sum(1)(2)(3) == 6; // 1 + 2 + 3
sum(5)(-1)(2) == 6
sum(6)(-1)(-2)(-3) == 0
sum(0)(1)(2)(3)(4)(5) == 15
*/

View file

@ -0,0 +1,19 @@
describe("sum", function(){
it("sum(1)(2) == 3", function(){
assert.equal(3, sum(1)(2));
});
it("sum(5)(-1)(2) == 6", function(){
assert.equal(6, sum(5)(-1)(2));
});
it("sum(6)(-1)(-2)(-3) == 0", function(){
assert.equal(0, sum(6)(-1)(-2)(-3));
});
it("sum(0)(1)(2)(3)(4)(5) == 15", function(){
assert.equal(15, sum(0)(1)(2)(3)(4)(5));
});
});