@extra-array/reduce-right
Version:
Reduces values from right, to a single value.
55 lines (41 loc) • 1.86 kB
Markdown
Reduces values from right, to a single value.
[:package:](https://www.npmjs.com/package/@extra-array/reduce-right)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/reduce-right)
[:vhs:](https://asciinema.org/a/332115)
[:moon:](https://www.npmjs.com/package/@extra-array/reduce-right.min)
[:scroll:](https://unpkg.com/@extra-array/reduce-right/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [reduce], [reduceRight].<br>
> Similar: [map], [filter], [reject], [reduce], [accumulate].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.reduceRight(x, fr, [acc]);
// x: an array
// fr: reduce function (acc, v, i, x)
// acc: initial value
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4];
array.reduceRight(x, (acc, v) => acc+v);
// 10
array.reduceRight(x, (acc, v) => acc+v, 100);
// 110
```
<br>
<br>
## References
- [Data.List.reduce: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:reduce)
- [Array.prototype.reduce: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)
- [iterable_reduce: PHP](https://www.php.net/manual/en/function.iterable-reduce.php)
- [Array.reduceRight: sugarjs](https://sugarjs.com/docs/#/ES5/Array/reduceRight)
[reduce]: https://github.com/nodef/extra-array/wiki/reduce
[reduceRight]: https://github.com/nodef/extra-array/wiki/reduceRight
[map]: https://github.com/nodef/extra-array/wiki/map
[filter]: https://github.com/nodef/extra-array/wiki/filter
[accumulate]: https://github.com/nodef/extra-array/wiki/accumulate
[reject]: https://github.com/nodef/extra-array/wiki/reject