Last active
November 5, 2019 16:59
-
-
Save dark4eg/3242f08ce0677f7c956ff9253bd3223f to your computer and use it in GitHub Desktop.
This file contains 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 ITEMS_MAX = 3000000; | |
const calcPercent = (items) => { | |
if (items.length > 3000000) { | |
return null; | |
} | |
const digits = items.map(i => Number(i)); | |
const sum = digits.reduce((a, item) => a + item, 0); | |
return digits.map(i => (100/(sum/i)).toFixed(3)); | |
}; | |
console.log('calcPercent params:', ['1.5', '3', '6', '1.5']); | |
console.log('calcPercent result:', calcPercent(['1.5', '3', '6', '1.5'])); | |
console.log('calcPercent params:', ['23.56', '63.47', '96.12', '0.15', '40.22', '80.44']); | |
console.log('calcPercent result:', calcPercent(['23.56', '63.47', '96.12', '0.15', '40.22', '80.44'])); | |
const simple = [...Array(3000000).keys()]; | |
console.log('calcPercent result:', calcPercent(simple)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment