-
-
Save mmloveaa/b2133cfc687092f97cf69c84fbb4e8ad to your computer and use it in GitHub Desktop.
Q26
This file contains hidden or 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
function getProducts(arr){ | |
var totalProd = arr.reduce(function(a,b){return a*b;}); | |
return arr.map(function(val){ | |
return totalProd/val; | |
}); | |
} | |
getProducts([5, 1, 3, 2]) | |
// return | |
// [6, 30, 10, 15] | |
// [1*3*2, 5*3*2, 5*1*2, 5*1*3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment