Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
This commit is contained in:
committed by
GitHub
parent
a07f84c8ec
commit
0bd52f8bd1
@ -1,58 +1,55 @@
|
||||
---
|
||||
title: Accumulator factory
|
||||
id: 594810f028c0303b75339ace
|
||||
title: Accumulator factory
|
||||
challengeType: 5
|
||||
forumTopicId: 302222
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A problem posed by <a href='https://en.wikipedia.org/wiki/Paul_Graham_(programmer)' target='_blank'>Paul Graham</a> is that of creating a function that takes a single (numeric) argument and which returns another function that is an accumulator. The returned accumulator function in turn also takes a single numeric argument, and returns the sum of all the numeric values passed in so far to that accumulator (including the initial value passed when the accumulator was created).
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
A problem posed by [Paul Graham](https://en.wikipedia.org/wiki/Paul_Graham_(programmer)) is that of creating a function that takes a single (numeric) argument and which returns another function that is an accumulator. The returned accumulator function in turn also takes a single numeric argument, and returns the sum of all the numeric values passed in so far to that accumulator (including the initial value passed when the accumulator was created).
|
||||
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Create a function that takes a number $n$ and generates accumulator functions that return the sum of every number ever passed to them.
|
||||
<strong>Rules:</strong>
|
||||
|
||||
**Rules:**
|
||||
|
||||
Do not use global variables.
|
||||
<strong>Hint:</strong>
|
||||
|
||||
**Hint:**
|
||||
|
||||
Closures save outer state.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>accumulator</code> should be a function.
|
||||
testString: assert(typeof accumulator === 'function');
|
||||
- text: <code>accumulator(0)</code> should return a function.
|
||||
testString: assert(typeof accumulator(0) === 'function');
|
||||
- text: <code>accumulator(0)(2)</code> should return a number.
|
||||
testString: assert(typeof accumulator(0)(2) === 'number');
|
||||
- text: Passing in the values 3, -4, 1.5, and 5 should return 5.5.
|
||||
testString: assert(testFn(5) === 5.5);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
`accumulator` should be a function.
|
||||
|
||||
```js
|
||||
function accumulator(sum) {
|
||||
|
||||
}
|
||||
assert(typeof accumulator === 'function');
|
||||
```
|
||||
|
||||
</div>
|
||||
`accumulator(0)` should return a function.
|
||||
|
||||
```js
|
||||
assert(typeof accumulator(0) === 'function');
|
||||
```
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
`accumulator(0)(2)` should return a number.
|
||||
|
||||
```js
|
||||
assert(typeof accumulator(0)(2) === 'number');
|
||||
```
|
||||
|
||||
Passing in the values 3, -4, 1.5, and 5 should return 5.5.
|
||||
|
||||
```js
|
||||
assert(testFn(5) === 5.5);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const testFn = typeof accumulator(3) === 'function' && accumulator(3);
|
||||
@ -62,13 +59,15 @@ if (testFn) {
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
## --seed-contents--
|
||||
|
||||
</section>
|
||||
```js
|
||||
function accumulator(sum) {
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function accumulator(sum) {
|
||||
@ -76,7 +75,4 @@ function accumulator(sum) {
|
||||
return sum += n;
|
||||
};
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user