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.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
597f24c1dda4e70f53c79c81 斐波那契序列 5 fibonacci-sequence

--description--

编写一个函数来生成第n Fibonacci数。

///

第n Fibonacci数由下式给出///

F n = F n-1 + F n-2

///

该系列的前两个术语是0,1。

///

因此该系列是0,1,1,2,3,5,8,13 ......

///

--hints--

fibonacci是一种功能。

assert(typeof fibonacci === 'function');

fibonacci(2)应该返回一个数字。

assert(typeof fibonacci(2) == 'number');

fibonacci(3)应该返回1.“)

assert.equal(fibonacci(3), 1);

fibonacci(5)应该返回3.“)

assert.equal(fibonacci(5), 3);

fibonacci(10)应该返回34.“)

assert.equal(fibonacci(10), 34);

--seed--

--seed-contents--

function fibonacci(n) {

}

--solutions--

function fibonacci(n) {
  let a = 0, b = 1, t;
  while (--n >= 0) {
    t = a;
    a = b;
    b += t;
  }
  return a;
}