Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Last active November 30, 2016 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/c0f44a845060bca73ab74be2ac7624f1 to your computer and use it in GitHub Desktop.
Save KinoAR/c0f44a845060bca73ab74be2ac7624f1 to your computer and use it in GitHub Desktop.
Array.Reduce JavaScript Tutorial Code
'use strict';
//Basic Reduce
let array = [1, 2, 3, 4, 5];
let result = array.reduce(function(sum, element) {
//Increase sum by element amount
sum += element;
console.log(sum); //1, 3, 6, 10, 15
return sum; //return the current sum for the next iteration
}, 0);
console.log(result); //15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment