Skip to content
Gallery
JS Fundamentals: Objects, Arrays, and Functions
Share
Explore
Functions

icon picker
Exercise: Implement reduce (bonus)

Prompt

The reduce method executes a user-supplied “reducer” callback function on each element of the array, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
Definition: reduce(collection, callback)
Example Usage:
const weapons = ['Revolver','Knife','Lead Pipe','Candlestick'];

const reducer = (previousValue, currentValue) => previousValue + currentValue;

console.log(array1.reduce(reducer));

// expected output: "RevolverKnifeLead PipeCandlestick"

Code here

Next 👉


©2021 for
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.