Skip to content

Instantly share code, notes, and snippets.

View fsjorgeluis's full-sized avatar
🏠
Working from home

Jorge Fernández fsjorgeluis

🏠
Working from home
View GitHub Profile
@fsjorgeluis
fsjorgeluis / reduceExamples.js
Created December 14, 2022 14:21 — forked from quangnd/reduceExamples.js
Some examples about reduce() in Javascript
//Example 1 - Calculate average value of an array (transform array into a single number)
var scores = [89, 76, 47, 95]
var initialValue = 0
var reducer = function (accumulator, item) {
return accumulator + item
}
var total = scores.reduce(reducer, initialValue)
var average = total / scores.length
/*Explain about function