Created
January 11, 2020 17:51
-
-
Save DawTaylor/c3d8c536ed8cc64abf7f62bd78e2105a 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 [_,__,...args] = process.argv | |
const isEven = (_, i) => (i % 2 === 0) | |
const isOdd = (_, i) => (i % 2 !== 0) | |
const parsedArgs = args.map(arg => parseInt(arg)) | |
const scores = parsedArgs.filter(isEven) | |
const weights = parsedArgs.filter(isOdd) | |
const getScore = (n, p) => n * p | |
const getScoresSum = (s, w) => | |
s.reduce(( acc, score, index) => | |
acc + getScore(score, w[index]) | |
,0) | |
const getWeightSum = (weights) => | |
weights.reduce((acc, weight) => | |
acc + weight | |
, 0) | |
const getMedia = (s, w) => getScoresSum(s, w) / getWeightSum(w) | |
console.log(getMedia(scores, weights)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment