https://www.codewars.com/kata/582cb0224e56e068d800003c
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:
Nathan loves cycling.
Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling.
You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value.
For example:
time = 3 ----> litres = 1
time = 6.7---> litres = 3
time = 11.8--> litres = 5
설명:
Nathan은 사이클링을 좋아합니다.
Nathan은 수분을 유지하는 것이 중요하다는 것을 알기 때문에, 사이클링을 하는 시간당 0.5리터의 물을 마십니다.
주어진 시간으로 Nathan이 마실 리터의 수를 가장 작은 값으로 반환해야 합니다.
예시:
time = 3 ----> litres = 1
time = 6.7---> litres = 3
time = 11.8--> litres = 5
풀이
주어진 시간을 2로 나누어 Math.floor로 소수점을 제거하고 반환했다.
코드
function litres(time) {
return Math.floor(time / 2);
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Moving Zeros To The End (5 kyu) / JavaScript (0) | 2022.12.31 |
---|---|
[Codewars] Is n divisible by x and y? (8 kyu) / JavaScript (0) | 2022.12.30 |
[Codewars] Ones and Zeros (7 kyu) / JavaScript (0) | 2022.12.28 |
[Codewars] Abbreviate a Two Word Name (8 kyu) / JavaScript (0) | 2022.12.27 |
[Codewars] Basic Mathematical Operations (8 kyu) / JavaScript (0) | 2022.12.26 |
댓글