Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jeremymouzin/085b976c806d55dd5735c6a6f0f4cfa8 to your computer and use it in GitHub Desktop.

Select an option

Save jeremymouzin/085b976c806d55dd5735c6a6f0f4cfa8 to your computer and use it in GitHub Desktop.
Exo CodinGame Benford Law
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