Apply new format to snippets and template
This commit is contained in:
@ -5,8 +5,8 @@ tags: function,array,intermediate
|
||||
|
||||
Builds an array, using an iterator function and an initial seed value.
|
||||
|
||||
Use a `while` loop and `Array.prototype.push()` to call the function repeatedly until it returns `false`.
|
||||
The iterator function accepts one argument (`seed`) and must always return an array with two elements ([`value`, `nextSeed`]) or `false` to terminate.
|
||||
- Use a `while` loop and `Array.prototype.push()` to call the function repeatedly until it returns `false`.
|
||||
- The iterator function accepts one argument (`seed`) and must always return an array with two elements ([`value`, `nextSeed`]) or `false` to terminate.
|
||||
|
||||
```js
|
||||
const unfold = (fn, seed) => {
|
||||
@ -20,4 +20,4 @@ const unfold = (fn, seed) => {
|
||||
```js
|
||||
var f = n => (n > 50 ? false : [-n, n + 10]);
|
||||
unfold(f, 10); // [-10, -20, -30, -40, -50]
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user