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

[Codewars] Round up to the next multiple of 5 (7 kyu) / JavaScript

by fluss 2023. 3. 4.

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

 

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:

Given an integer as input, can you round it to the next (meaning, "greater than or equal") multiple of 5?

Examples:

input:    output:
0    ->   0
2    ->   5
3    ->   5
12   ->   15
21   ->   25
30   ->   30
-2   ->   0
-5   ->   -5
etc.

Input may be any positive or negative integer (including 0).

You can assume that all inputs are valid integers.

 

코드

function roundToNext5(n){
  return Math.ceil(n / 5) * 5;
}

댓글