Skip to content

Instantly share code, notes, and snippets.

@DawTaylor
Created January 11, 2020 17:51
Show Gist options
  • Save DawTaylor/c3d8c536ed8cc64abf7f62bd78e2105a to your computer and use it in GitHub Desktop.
Save DawTaylor/c3d8c536ed8cc64abf7f62bd78e2105a to your computer and use it in GitHub Desktop.
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