This commit adds the pre-existing challenge guide topics in the forum to the forntmatter of their challenge markdown files.
2.2 KiB
2.2 KiB
id, title, isRequired, challengeType, forumTopicId
id | title | isRequired | challengeType | forumTopicId |
---|---|---|---|---|
a97fd23d9b809dac9921074f | Arguments Optional | true | 5 | 14271 |
Description
addTogether(2, 3)
should return 5
, and addTogether(2)
should return a function.
Calling this returned function with a single argument will then return the sum:
var sumTwoAnd = addTogether(2);
sumTwoAnd(3)
returns 5
.
If either argument isn't a valid number, return undefined.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Instructions
Tests
tests:
- text: <code>addTogether(2, 3)</code> should return 5.
testString: assert.deepEqual(addTogether(2, 3), 5);
- text: <code>addTogether(2)(3)</code> should return 5.
testString: assert.deepEqual(addTogether(2)(3), 5);
- text: <code>addTogether("http://bit.ly/IqT6zt")</code> should return undefined.
testString: assert.isUndefined(addTogether("http://bit.ly/IqT6zt"));
- text: <code>addTogether(2, "3")</code> should return undefined.
testString: assert.isUndefined(addTogether(2, "3"));
- text: <code>addTogether(2)([3])</code> should return undefined.
testString: assert.isUndefined(addTogether(2)([3]));
Challenge Seed
function addTogether() {
return false;
}
addTogether(2,3);
Solution
function addTogether() {
var a = arguments[0];
if (toString.call(a) !== '[object Number]') return;
if (arguments.length === 1) {
return function(b) {
if (toString.call(b) !== '[object Number]') return;
return a + b;
};
}
var b = arguments[1];
if (toString.call(b) !== '[object Number]') return;
return a + arguments[1];
}