Skip to content

Commit c7813cb

Browse files
committed
Added algorithm for checkinf if a number is square free or not
1 parent af0b0bb commit c7813cb

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Maths/isSquareFree.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function isSquareFree(num = 0) {
2+
for (let i = 2; i < Math.round(Math.sqrt(num) + 1); i++) {
3+
debugger;
4+
if (num % Math.pow(i, 2) === 0) return false;
5+
}
6+
return true;
7+
}
8+
9+
const squareFrees = [1, 3, 5, 6, 13, 15, 17, 19, 21, 22, 26, 29, 34, 35, 38];
10+
const notSquareFrees = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40];
11+
12+
squareFrees.forEach(s => console.log(_isSquareFree(s)));
13+
notSquareFrees.forEach(n => console.log(_isSquareFree(n)));

0 commit comments

Comments
 (0)