Skip to content

Instantly share code, notes, and snippets.

@mattraykowski
Created November 6, 2014 16:50
Show Gist options
  • Save mattraykowski/3718fd8fa02f730dab56 to your computer and use it in GitHub Desktop.
Save mattraykowski/3718fd8fa02f730dab56 to your computer and use it in GitHub Desktop.
Sample Interview Question Solution
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