flatmap for arrays

PHOTO EMBED

Tue Dec 24 2024 22:08:11 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale

  const bankdeposits = accounts
    .flatMap(item => item.movements) // combines all arrays into one
    .filter(item => item > 0)
    .reduce((total, item) => (total += item), 0);
  console.log(bankdeposits); // 25180
content_copyCOPY