Created
May 17, 2019 18:34
-
-
Save jasonwaters/fb8242d4768d40a539a67a78082d9fdf to your computer and use it in GitHub Desktop.
Return an Array of integers by multiplying all elements in given array except the current index integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = [1,2,3, 2]; | |
function multiplify(arr) { | |
const total = arr.reduce((acc, item) => { | |
return acc * item; | |
}, 1); | |
return arr.map((el) => total/el) | |
} | |
console.log(multiplify(a)); |
Author
jasonwaters
commented
May 22, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment