Last active
March 19, 2018 04:05
-
-
Save naveedn/93b7eaa01da0dbc9d3a1e7e45894cf15 to your computer and use it in GitHub Desktop.
Medium Article Snippet
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
const input = [1,3,5,7]; | |
function product(inputArr) { | |
const output = []; | |
for (let i = 0; i < inputArr.length; i++) { | |
let product = 1; | |
for (let j = 0; j < inputArr.length; j++) { | |
if (i !== j) { | |
product *= inputArr[j]; | |
} | |
} | |
output.push(product); | |
product = 1; | |
} | |
return output; | |
} | |
console.log(product(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Algorithmic Complexity:
Speed: O(n*2)
Space: O(n)
Next Approach: https://gist.github.com/naveedn/b16bd0a15ba089c58187eeacf4448efa