JSFiddle - React, Tailwind, and code Playground
JavaScript
/*
Calcs the time needed to boil given eggs quantity
@param {Number} eggs - number of eggs needs to be boiled
@return {Number} minutes needed to boil all the eggs
*/
function calcBoilTime(eggs) {
const BOIL_TIME = 5;
const POT_CAPACITY = 8;
return Math.ceil(eggs / POT_CAPACITY) * BOIL_TIME;
}
function assert(func, assertValue, testValue) {
const actualValue = func(assertValue);
const errorString = `Calculation is wrong, expected ${testValue}, but got ${actualValue}`;
console.assert(actualValue === testValue, errorString);
}
assert(calcBoilTime, 5, 5);
assert(calcBoilTime, 10, 10);
assert(calcBoilTime, 25, 20);
assert(calcBoilTime, 65, 45);
console.log('done working');