https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097
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:
Introduction
The first century spans from the year 1 up to and including the year 100, the second century - from the year 101 up to and including the year 200, etc.
Task
Given a year, return the century it is in.
Examples
1705 --> 18
1900 --> 19
1601 --> 17
2000 --> 20
소개
The first century spans from the year 1 up to and including the year 100, the second century - from the year 101 up to and including the year 200, etc.
1세기는 1년부터 100년까지, 2세기는 101년부터 200까지, 등등입니다.
작업
Given a year, return the century it is in.
연도가 주어지면 세기를 반환하세요
예시
1705 --> 18
1900 --> 19
1601 --> 17
2000 --> 20
풀이
주어진 연도를 100으로 나눈 몫을 반환하는데 주어진 연도를 100으로 나눈 나머지가 0보다 크다면 1을 더해서 반환해 주었다.
코드
function century(year) {
let cen = parseInt(year / 100);
return year % 100 > 0 ? cen + 1 : cen;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Abbreviate a Two Word Name (8 kyu) / JavaScript (0) | 2022.12.27 |
---|---|
[Codewars] Basic Mathematical Operations (8 kyu) / JavaScript (0) | 2022.12.26 |
[Codewars] Sum of odd numbers (7 kyu) / JavaScript (1) | 2022.12.23 |
[Codewars] Detect Pangram (6 kyu) / JavaScript (0) | 2022.12.22 |
[Codewars] Is this a triangle? (7 kyu) / JavaScript (0) | 2022.12.21 |
댓글