Travis build: 1402

This commit is contained in:
30secondsofcode
2018-01-24 14:39:25 +00:00
parent cfcb8a2ba1
commit f738884baf
3 changed files with 29 additions and 4 deletions

View File

@ -134,6 +134,7 @@ average(1, 2, 3);
* [`pullAtIndex`](#pullatindex)
* [`pullAtValue`](#pullatvalue)
* [`reducedFilter`](#reducedfilter)
* [`reduceSuccessive`](#reducesuccessive)
* [`remove`](#remove)
* [`sample`](#sample)
* [`sampleSize`](#samplesize)
@ -1693,6 +1694,29 @@ reducedFilter(data, ['id', 'name'], item => item.age > 24); // [{ id: 2, name: '
<br>[⬆ Back to top](#table-of-contents)
### reduceSuccessive
Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values.
Use `Array.reduce()` to apply the given function to the given array, storing each new result.
```js
const reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
```
<details>
<summary>Examples</summary>
```js
reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6, 10, 15, 21]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### remove
Removes elements from an array for which the given function returns `false`.

File diff suppressed because one or more lines are too long

View File

@ -6,9 +6,7 @@ Use `Array.reduce()` to apply the given function to the given array, storing eac
```js
const reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)),res), [
acc,
]);
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
```
```js