Skip to content

Instantly share code, notes, and snippets.

@dottedsquirrel
Created August 30, 2019 01:57
Show Gist options
  • Save dottedsquirrel/2dcf5b8c8eb68d7d064fd07bf2237616 to your computer and use it in GitHub Desktop.
Save dottedsquirrel/2dcf5b8c8eb68d7d064fd07bf2237616 to your computer and use it in GitHub Desktop.
JavaScript array reduce()
let numbers = [100, 20, 10];
// result will return 70 as the value
// The function inside reduce will run twice.
// the first time, x = 100, y = 20
// the second time, x = 80, y = 10
result = numbers.reduce((x, y) => { return x - y; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment