Skip to content

Instantly share code, notes, and snippets.

@naveedn
Last active March 19, 2018 04:08
Show Gist options
  • Save naveedn/ede7ccf065a354fc8b0a47e50ef37ab7 to your computer and use it in GitHub Desktop.
Save naveedn/ede7ccf065a354fc8b0a47e50ef37ab7 to your computer and use it in GitHub Desktop.
Medium Article Snippet
const input = [1,3,5,7];
const fn = (inputArr) =>
inputArr
.map(x => [...inputArr])
.map((x, i) => {
const firstPart = x.slice(0, i);
const lastPart = x.slice(i+1);
return [...firstPart, ...lastPart];
})
.map(x => x.reduce((elem, acc) => acc * elem));
console.log(fn(input));
@naveedn
Copy link
Author

naveedn commented Mar 19, 2018

Algorithmic Complexity:

Speed: O(n2)
Space: O(n
2)

Alternative Approach: https://gist.github.com/naveedn/9ad30d2f9bc6789aea24f1e5156d6934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment