https://www.codewars.com/kata/5a6663e9fd56cb5ab800008b
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:

Kata Task
I have a cat and a dog.
I got them at the same time as kitten/puppy. That was humanYears years ago.
Return their respective ages now as [humanYears,catYears,dogYears]
NOTES:
- humanYears >= 1
- humanYears are whole numbers only
Cat Years
- 15 cat years for first year
- +9 cat years for second year
- +4 cat years for each year after that
Dog Years
- 15 dog years for first year
- +9 dog years for second year
- +5 dog years for each year after that
References
- http://www.catster.com/cats-101/calculate-cat-age-in-cat-years
- http://www.slate.com/articles/news_and_politics/explainer/2009/05/a_dogs_life.html
If you liked this Kata there is another related one here
코드
var humanYearsCatYearsDogYears = function(humanYears) {
if(humanYears === 1) return [humanYears, 15, 15];
if(humanYears === 2) return [humanYears, 24, 24];
return [humanYears, 24 + (humanYears - 2) * 4, 24 + (humanYears - 2) * 5];
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Reverse List Order (8 kyu) / JavaScript (0) | 2023.04.13 |
---|---|
[Codewars] Student's Final Grade (8 kyu) / JavaScript (0) | 2023.04.13 |
[Codewars] Area of a Square (8 kyu) / JavaScript (0) | 2023.04.12 |
[Codewars] Correct the mistakes of the character recognition software (8 kyu) / JavaScript (0) | 2023.04.11 |
[Codewars] Meeting (6 kyu) / JavaScript (0) | 2023.04.11 |
댓글