From 34adaed7992e6f7e5ea7aa7fcda86c6c2caa5f04 Mon Sep 17 00:00:00 2001 From: koronya Date: Thu, 14 May 2026 20:44:46 +0900 Subject: [PATCH] [JS][7kyu] Music 1: How Many Quarter Notes? --- .../music-1-how-many-quarter-notes/koronya.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 codewars/7kyu/music-1-how-many-quarter-notes/koronya.js diff --git a/codewars/7kyu/music-1-how-many-quarter-notes/koronya.js b/codewars/7kyu/music-1-how-many-quarter-notes/koronya.js new file mode 100644 index 000000000..0a01d07a1 --- /dev/null +++ b/codewars/7kyu/music-1-how-many-quarter-notes/koronya.js @@ -0,0 +1,30 @@ +// [JS][7kyu] Music 1: How Many Quarter Notes? +// music-1-how-many-quarter-notes +// https://www.codewars.com/kata/69c2f04a1294ffc95c526d9e/train/javascript + +const findQuarterNotes = (timeSignature) => { + const [a, b] = timeSignature.split('/').map(Number) + if ((Math.log(b) / Math.log(2)) % 1 !== 0) { + return null + } + return Math.floor((a / b) * 4) +} + +findQuarterNotes('4/4') === 4 +findQuarterNotes('3/4') === 3 + +findQuarterNotes('6/8') === 3 +findQuarterNotes('9/8') === 4 + +findQuarterNotes('1/8') === 0 +findQuarterNotes('1/16') === 0 + +findQuarterNotes('9/0') === null +findQuarterNotes('7/3') === null +findQuarterNotes('6/5') === null +findQuarterNotes('5/6') === null +findQuarterNotes('3/7') === null +findQuarterNotes('0/9') === null + +findQuarterNotes('7/1') === 28 +findQuarterNotes('6/2') === 12