Apply new format to snippets and template
This commit is contained in:
@ -5,11 +5,11 @@ tags: math,intermediate
|
||||
|
||||
Evaluates the binomial coefficient of two integers `n` and `k`.
|
||||
|
||||
Use `Number.isNaN()` to check if any of the two values is `NaN`.
|
||||
Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.
|
||||
Check if `n - k` is less than `k` and switch their values accordingly.
|
||||
Loop from `2` through `k` and calculate the binomial coefficient.
|
||||
Use `Math.round()` to account for rounding errors in the calculation.
|
||||
- Use `Number.isNaN()` to check if any of the two values is `NaN`.
|
||||
- Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.
|
||||
- Check if `n - k` is less than `k` and switch their values accordingly.
|
||||
- Loop from `2` through `k` and calculate the binomial coefficient.
|
||||
- Use `Math.round()` to account for rounding errors in the calculation.
|
||||
|
||||
```js
|
||||
const binomialCoefficient = (n, k) => {
|
||||
@ -26,4 +26,4 @@ const binomialCoefficient = (n, k) => {
|
||||
|
||||
```js
|
||||
binomialCoefficient(8, 2); // 28
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user