Created
November 6, 2014 16:50
-
-
Save mattraykowski/3718fd8fa02f730dab56 to your computer and use it in GitHub Desktop.
Sample Interview Question Solution
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
var get_products_of_all_ints_except_at_index = function(arrayOfInts) { | |
var productArray = []; | |
arrayOfInts.forEach(function(element, index) { | |
var holderArray = arrayOfInts.slice(0); | |
holderArray.splice(index, 1); | |
var product = holderArray.reduce(function(previous, current) { | |
return previous*current; | |
}); | |
productArray.push(product); | |
}); | |
return productArray; | |
}; | |
var integers = [1, 7, 3, 4]; | |
var result = get_products_of_all_ints_except_at_index(integers); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment