Skip to content

Instantly share code, notes, and snippets.

@NhanKhangg98
Created September 11, 2022 09:41
Show Gist options
  • Save NhanKhangg98/8d5a74340f7866bf50f35a2c0cc6a6f9 to your computer and use it in GitHub Desktop.
Save NhanKhangg98/8d5a74340f7866bf50f35a2c0cc6a6f9 to your computer and use it in GitHub Desktop.
const trips = [
{to:'Brazil',distance:1000},
{to:'Chine',distance: 2500},
{to:'India',distance: 3000}
]
const initialValue = 0;
const sumWithInitial = trips.reduce(
(previousValue, currentValue) => previousValue += currentValue.distance,
initialValue
);
console.log(sumWithInitial);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment