From b57a37f5e72f1be8595db08dd6c4ff43c763011f Mon Sep 17 00:00:00 2001 From: koronya Date: Sat, 28 Feb 2026 22:02:37 +0900 Subject: [PATCH] [JS][7kyu] Round to nearest 0 or 5 --- .../7kyu/round-to-nearest-0-or-5/koronya.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 codewars/7kyu/round-to-nearest-0-or-5/koronya.js diff --git a/codewars/7kyu/round-to-nearest-0-or-5/koronya.js b/codewars/7kyu/round-to-nearest-0-or-5/koronya.js new file mode 100644 index 000000000..2a0e83c79 --- /dev/null +++ b/codewars/7kyu/round-to-nearest-0-or-5/koronya.js @@ -0,0 +1,17 @@ +// [JS][7kyu] Round to nearest 0 or 5 +// round-to-nearest-0-or-5 +// https://www.codewars.com/kata/582f52208278c6be55000067/train/javascript + +// return the list with all numbers rounded to nearest 0 or 5 +const roundToFive = (numbers) => { + return numbers.map((num) => { + const remainder = num % 5 + if (remainder < 2.5) { + return num - remainder + } else { + return num + (5 - remainder) + } + }) +} + +roundToFive([34.5, 56.2, 11, 13])