Created
February 12, 2020 09:51
-
-
Save jaxxreal/c73d4d6e93f577be83c7df33f2fc2e1e to your computer and use it in GitHub Desktop.
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
function makePercent(inputArr) { | |
const sum = inputArr.reduce((sum, next) => sum + parseFloat(next), 0); | |
return inputArr.map(v => (parseFloat(v) / sum * 100).toFixed(3)); | |
} | |
// time complexity O(2n) | |
// space complexity O(n+1) | |
// array length must be lower than 10.000.000 (10 millions) to make it run under 5s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment