I’m looking to get the average of each index in a matrix row in JS
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Then returning a list with the average of each row index : [4, 5, 6]
Would I create a loop, save each index to a list, add them up, and divide them, then form new list with averages?
I feel like there is probably a simpler way.
2
Answers
Easy peasy here how you can achieve the average via given matrix :
You can use
Array#reduce
andArray#map
methods as follows: