Let’s Talk about Higher-Order Functions Pt. 2

Tiffany Kanjanabout
1 min readMar 15, 2021

.reduce()

Definition + Syntax — MDN

/* 
Definition
:
The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.
*/
// Syntax:
arr.reduce(callback( accumulator, currentValue, [, index[, array]] )[, initialValue])

When to Use:

reduce() allows us to loop over values in an array and return a single output. At its most basic use, you can sum an array of numbers. You can also use other methods inside the reduce like conditional statements or other applicatives.

In Action:

A simple .reduce() used in A Very Big Sum on HackerRank.

const aVeryBigSum = (array) => {
let sum = 0;
return array.reduce((sum, currentValue) => {
return sum += currentValue
});
};

.includes()

Definition + Syntax — MDN

/* 
Definition
:
The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
*/
// Syntax:
arr.includes(valueToFind[, fromIndex])

When to Use:

includes()

In Action:

--

--

Tiffany Kanjanabout

Full stack web developer. Frontend and design enthusiast. Avid rock climber and amateur photographer.