js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Cat years, Dog years #357

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 5 years ago

https://www.codewars.com/kata/cat-years-dog-years/train/javascript

RazvanBugoi commented 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];
        };
}
RazvanBugoi commented 4 years ago

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)];
        };
}