From 7501a69736a3fb2b9faa18b8258bb07168815de7 Mon Sep 17 00:00:00 2001 From: koronya Date: Thu, 7 May 2026 23:39:50 +0900 Subject: [PATCH] [JS][7kyu] Are they square? --- codewars/7kyu/are-they-square/koronya.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 codewars/7kyu/are-they-square/koronya.js diff --git a/codewars/7kyu/are-they-square/koronya.js b/codewars/7kyu/are-they-square/koronya.js new file mode 100644 index 000000000..325b07ac4 --- /dev/null +++ b/codewars/7kyu/are-they-square/koronya.js @@ -0,0 +1,18 @@ +// [JS][7kyu] Are they square? +// are-they-square +// https://www.codewars.com/kata/56853c44b295170b73000007/train/javascript + +const isSquare = (arr) => { + if (arr.length === 0) { + return undefined + } + return arr.every((num) => { + const sqrt = Math.sqrt(num) + return sqrt === Math.floor(sqrt) + }) +} + +isSquare([1, 4, 9, 16, 25, 36]) === true +isSquare([1, 2, 3, 4, 5, 6]) === false +isSquare([]) === undefined +isSquare([1, 2, 4, 15]) === false