Skip to content

Instantly share code, notes, and snippets.

@funador
Last active July 25, 2018 21:29
Show Gist options
  • Save funador/2dd7feb649c02068cafe83ddca3ff430 to your computer and use it in GitHub Desktop.
Save funador/2dd7feb649c02068cafe83ddca3ff430 to your computer and use it in GitHub Desktop.
const arrToManipulate = [3, 5, 9, 2]
const atIndex = arr => {
const retArr = []
for(let i = 0; i < arr.length; i ++) {
let total = 1
for (let j = 0; j < arr.length; j++) {
if(j !== i) {
total *= arr[j]
}
}
retArr.push(total)
}
return retArr
}
atIndex(arrToManipulate) // [90, 54, 30, 135]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment