Ad

A trainee on a coding course has milestones set along the way to measure their progress.

On each milestone day, the trainee measures their progress against the milestone factors and determines whether they are Behind, At, or Beyond the milestone.

The milestone factors could be anything, but right now they are:

  • Attendance Percentage
  • Codewars Rank
  • Tests
  • Number of Pull Requests

Write a function, computeProgress, that checks the trainees milestone factor values against the milestone values and returns a string of either:

  • 'Behind Milestone'
  • 'At Milestone'
  • 'Beyond Milestone'

Discover, using the tests, how milestone progress is computed. You can write your own tests to help you. You only need to handle a single milestone day in this kata.

const Deepa = {
  attendance: 100,
  tests: 4,
  codewars: 7,
  pullRequests: 12
}
const Bilal = {
  attendance: 95,
  tests: 3,
  codewars: 7,
  pullRequests: 12
}
const milestoneDay = {
  attendance: 100,
  tests: 4,
  codewars: 7,
  pullRequests: 12
}

const computeProgress = (trainee, milestone) => {
  const comparator = Object.entries(milestoneDay).length * 2;
  const checkMilestone = (factor, milestone) => factor > milestone ? 3 : factor === milestone ? 2 : 1; 
  // codewars ranks go down
  const checkCodewars = (factor, milestone) => factor < milestone ? 3 : factor === milestone ? 2 : 1; 

  // 1 behind, 2 at, 3 ahead, and there are currently 4 measures 
  // therefore at each milestone 8 is the currently the comparator
  

  let attendance = checkMilestone(trainee.attendance, milestone.attendance); 
  let codewars = checkCodewars(trainee.codewars, milestone.codewars); 
  let tests = checkMilestone(trainee.tests, milestone.tests); 
  let pulls = checkMilestone(trainee.pullRequests, milestone.pullRequests); 
  
  const sumFactors = codewars + tests + attendance + pulls;
  
  return sumFactors > comparator ? 'Beyond Milestone' : sumFactors === comparator ? 'At Milestone' : 'Behind Milestone'
  
}