Closed RazvanBugoi closed 4 years ago
let humanYearsCatYearsDogYears = function(humanYears) {
if (humanYears === 1) {
return [1, 15, 15];
} else if (humanYears === 2) {
return [2, 24, 24];
} else {
let catYears = 24 + 4 * (humanYears - 2);
let dogYears = 24 + 5 * (humanYears - 2);
return [humanYears, catYears, dogYears];
};
}
Shortened version:
let humanYearsCatYearsDogYears = function(humanYears) {
if (humanYears === 1) {
return [1, 15, 15];
} else if (humanYears === 2) {
return [2, 24, 24];
} else {
return [humanYears, 24 + 4 * (humanYears - 2), 24 + 5 * (humanYears - 2)];
};
}
https://www.codewars.com/kata/cat-years-dog-years/train/javascript