reduce
Reduces a Map to a single value by applying a function to each entry, in insertion order.
Available since v3.0.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
map | ReadonlyMap<K, V> | The Map to reduce |
fn | function | Function invoked with (accumulator, value, key) |
initial | R | Initial accumulator value |
Returns
Section titled “Returns”R — The final accumulator value
Examples
Section titled “Examples”Sum all values
Section titled “Sum all values”Reduces a Map of numbers to their total.
Build an array of keys
Section titled “Build an array of keys”Reduce can produce a completely different shape than the map values.
