Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Created June 5, 2020 15:43
Show Gist options
  • Save dinocarl/3c25a40873c6c1b67b4ada2841c4d815 to your computer and use it in GitHub Desktop.
Save dinocarl/3c25a40873c6c1b67b4ada2841c4d815 to your computer and use it in GitHub Desktop.
Takes an array of numbers and returns their average, rounded to the thousands place
const toThsnds = compose(
multiply(1000),
Math.round,
multiply(1/1000)
);
const avgToThsnds = (arr) => compose(
toThsnds,
multiply(1/length(arr)),
reduce(add, 0)
)(arr);
avgToThsnds([100000, 110000, 150000]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment