Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jpoechill
Last active May 25, 2017 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpoechill/ecba8e2dba446543731ba48d7b3139b1 to your computer and use it in GitHub Desktop.
Save jpoechill/ecba8e2dba446543731ba48d7b3139b1 to your computer and use it in GitHub Desktop.
Product of All Other Numbers via. InterviewCake
function getProductsOfAllIntsExceptAtIndex (arr) {
var productsOfArr = []
for (var i = 0; i < arr.length; i++) {
var clone = arr.slice(0)
var removed = clone.splice(i, 1)
productsOfArr.push(getProductOfArr(clone));
}
console.log(productsOfArr);
}
function getProductOfArr (arr) {
var product = 1
for (var t = 0; t < arr.length; t++) {
product = product * arr[t]
}
return product
}
getProductsOfAllIntsExceptAtIndex([1, 7, 3, 10]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment