Created
April 9, 2021 09:01
-
-
Save mqklin/5a35f46017ea2ec67def0841f91c1f23 to your computer and use it in GitHub Desktop.
get random performance
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 getRandoms() { | |
const examples = 100; | |
for (var i = 0; i < examples; i++) { | |
const arr = Array(getRandomInt(1, 6)).fill(null); | |
for (var j = 0; j < arr.length; j++) { | |
arr[j] = getRandomInt(-50, 150); | |
} | |
console.log(`[${arr.map(a => a + '%').join(', ')}] => `, perf(arr).toFixed(2) + '%'); | |
} | |
} | |
function perf(arr) { | |
var x = Math.sqrt(arr.slice(1).reduce( | |
(acc, perf) => { | |
return acc * (1 + perf / 100) | |
}, | |
1 + arr[0] / 100 | |
)); | |
return 1000 * (x / (1 + x) - 0.5); | |
} | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment