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'
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("Deepa should be At Milestone", function() {
assert.equal('At Milestone', computeProgress(Deepa,milestoneDay))
});
it("Bilal should be Behind Milestone", function() {
assert.equal('Behind Milestone', computeProgress(Bilal,milestoneDay))
});
});