Created
March 2, 2022 18:27
-
-
Save jeremymouzin/085b976c806d55dd5735c6a6f0f4cfa8 to your computer and use it in GitHub Desktop.
Exo CodinGame Benford Law
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
| let total = arr.reduce((res,v) => res += v[1], 0); | |
| arr = arr.map(value => [value[0], value[1] / total * 100]); | |
| let benfordLaw = { | |
| '1': 30.1, | |
| '2': 17.6, | |
| '3': 12.5, | |
| '4': 9.7, | |
| '5': 7.9, | |
| '6': 6.7, | |
| '7': 5.8, | |
| '8': 5.1, | |
| '9': 4.6, | |
| }; | |
| let percentages = Object.fromEntries(arr); | |
| for (let number in benfordLaw) { | |
| if (Math.abs(percentages[number] - benfordLaw[number]) > 10) { | |
| console.log("true"); | |
| return; | |
| } | |
| } | |
| console.log("false"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment