I have 2 d array:
val arr =Array(Array(2,1),Array(3,1),Array(4,1))
I should multiply all inner 1st elements and sum all inner 2nd elements to get as result:
Array(24,3)
I`m looking a way to use map there, something like :
arr.map(a=>Array(a(1stElemnt).product , a(2ndElemnt).sum ))
Any suggestion Regards.
foldLeftinstead.maphere.maptakes a collection and a function to apply to each element an return a new collection of the same size. Whereas, you actually want to reduce all the elements in the collection into a single element, that is what folding does.