Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a97fd23d9b809dac9921074f 可选参数 5 14271 arguments-optional

--description--

创建一个将两个参数相加的函数。如果调用时只传入了一个参数,则应返回一个接收新的参数的函数。待传入下一个参数后,再返回与之前传入的参数之和。

比如,addTogether(2, 3) 应该返回 5。而 addTogether(2) 应该返回一个函数。

调用这个返回的函数,为它传入一个值,然后再返回总和:

var sumTwoAnd = addTogether(2);

sumTwoAnd(3) 此时应返回 5

任何时候,只要任一传入的参数不是数字,就应返回 undefined

--hints--

addTogether(2, 3) 应返回 5。

assert.deepEqual(addTogether(2, 3), 5);

addTogether(23, 30) 应返回 53。

assert.deepEqual(addTogether(23, 30), 53);

addTogether(5)(7) 应返回 12。

assert.deepEqual(addTogether(5)(7), 12);

addTogether("http://bit.ly/IqT6zt") 应返回 undefined。

assert.isUndefined(addTogether('http://bit.ly/IqT6zt'));

addTogether(2, "3") 应返回 undefined。

assert.isUndefined(addTogether(2, '3'));

addTogether(2)([3]) 应返回 undefined。

assert.isUndefined(addTogether(2)([3]));

--seed--

--seed-contents--

function addTogether() {
  return false;
}

addTogether(2,3);

--solutions--

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];
}