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