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

71 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 598de241872ef8353c58a7a2
title: 评估二项式系数
challengeType: 5
videoUrl: ''
dashedName: evaluate-binomial-coefficients
---
# --description--
<p>写一个函数来计算给定n和k值的二项式系数。 </p><p>推荐这个公式: </p> $ \\ binom {n} {k} = \\ frac {n} {nkk} = \\ frac {nn-1n-2\\ ldotsn-k + 1} { kk-1k-2\\ ldots 1} $
# --hints--
`binom`是一个功能。
```js
assert(typeof binom === 'function');
```
`binom(5,3)`应该返回10。
```js
assert.equal(binom(5, 3), 10);
```
`binom(7,2)`应该返回21。
```js
assert.equal(binom(7, 2), 21);
```
`binom(10,4)`应该返回210。
```js
assert.equal(binom(10, 4), 210);
```
`binom(6,1)`应该返回6。
```js
assert.equal(binom(6, 1), 6);
```
`binom(12,8)`应该返回495。
```js
assert.equal(binom(12, 8), 495);
```
# --seed--
## --seed-contents--
```js
function binom(n, k) {
}
```
# --solutions--
```js
function binom(n, k) {
let coeff = 1;
for (let i = n - k + 1; i <= n; i++) coeff *= i;
for (let i = 1; i <= k; i++) coeff /= i;
return coeff;
}
```