0

How to do Array to array multiplication in Javascript?

How do we multiply an array using another array of equal elements and the answer should be in an array too. Example: [2,3,5] × [4,6,8] Answer = [8,18,40] How do we achieve this example using JavaScript?

5th Nov 2022, 7:50 PM
Isaac Ugwuanyi
4 Respostas
+ 2
const matmul = (arr1, arr2) => arr1.map((x, i) => x * arr2[i]); https://code.sololearn.com/cmIQzNpmbGD9/?ref=app
5th Nov 2022, 9:31 PM
Tibor Santa
Tibor Santa - avatar
+ 1
We can accept the array to be a matrix then we can use matrix multiplication. But we must remember that in matrices, A × B ≠ B × A always
5th Nov 2022, 8:03 PM
Just Some Random Guy
Just Some Random Guy - avatar
+ 1
Tibor Santa thanks so much 🙏, This is exactly what I was looking for 😊.
5th Nov 2022, 9:38 PM
Isaac Ugwuanyi
0
Snehil Pandey [OFFLINE] And how do we apply this matrix multiplication? . I haven't come across it yet on my JavaScript tutorial. Can you give a code example in Javascript please.
5th Nov 2022, 9:17 PM
Isaac Ugwuanyi