From 20ba0e5d2c5c48c0314b5e134ca0f7ee23535d51 Mon Sep 17 00:00:00 2001 From: koronya Date: Tue, 21 Apr 2026 03:39:47 +0900 Subject: [PATCH] [JS][7kyu] Show multiples of 2 numbers within a range --- .../koronya.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 codewars/7kyu/show-multiples-of-2-numbers-within-a-range/koronya.js diff --git a/codewars/7kyu/show-multiples-of-2-numbers-within-a-range/koronya.js b/codewars/7kyu/show-multiples-of-2-numbers-within-a-range/koronya.js new file mode 100644 index 000000000..5a07c2d2d --- /dev/null +++ b/codewars/7kyu/show-multiples-of-2-numbers-within-a-range/koronya.js @@ -0,0 +1,21 @@ +// [JS][7kyu] Show multiples of 2 numbers within a range +// show-multiples-of-2-numbers-within-a-range +// https://www.codewars.com/kata/583989556754d6f4c700018e/train/javascript + +const getGcd = (a, b) => (b === 0 ? a : getGcd(b, a % b)) +const getLcm = (a, b) => (a * b) / getGcd(a, b) + +const multiples = (s1, s2, s3) => { + const result = [] + const lcm = getLcm(s1, s2) + for (let i = lcm; i < s3; i += lcm) { + if (i % s1 === 0 || i % s2 === 0) { + result.push(i) + } + } + return result +} + +multiples(2, 4, 40) +multiples(13, 5, 800) +multiples(13, 15, 800)