본문 바로가기
알고리즘/Codewars

[Codewars] Beginner Series #2 Clock (8 kyu) / JavaScript

by fluss 2022. 10. 24.

https://www.codewars.com/kata/55f9bca8ecaa9eac7100004a

 

Codewars - Achieve mastery through coding practice and developer mentorship

Coding practice 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:

Clock shows h hours, m minutes and s seconds after midnight.

Your task is to write a function which returns the time since midnight in milliseconds.

 

Example:

h = 0
m = 1
s = 1

result = 61000

Input constraints:

  • 0 <= h <= 23
  • 0 <= m <= 59
  • 0 <= s <= 59
 

설명:

시계는 자정 이후 h 시간, m분, s초를 보여줍니다.

자정 이후의 시간을 밀리 초로 반환하는 함수를 작성하세요.

 

예시:

h = 0
m = 1
s = 1

result = 61000

입력 제한:

  • 0 <= h <= 23
  • 0 <= m <= 59
  • 0 <= s <= 59

 

풀이

h, m, s를 각각 밀리 초로 바꾼 다음 더해서 반환해주었다.

 

코드

function past(h, m, s){
  h = h * 60 * 60 * 1000;
  m = m * 60 * 1000;
  s = s * 1000;
  return h + m + s;
}

 

댓글