Skip to content

Instantly share code, notes, and snippets.

@WangNingning1994
Created January 12, 2023 02:55
Show Gist options
  • Save WangNingning1994/30f7a55c86e110a96df8c351d97e98df to your computer and use it in GitHub Desktop.
Save WangNingning1994/30f7a55c86e110a96df8c351d97e98df to your computer and use it in GitHub Desktop.
double reduce to calculate total value of array that holding number
const numArr = [ [1,2,3], [4,5,6] ];
const initialValue = 0;
const totalNum = numArr.reduce(
(acc, curr) => acc + curr.reduce((acc_, curr_) => acc_ + curr_, 0),
initialValue
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment