Last active
May 19, 2024 15:42
-
-
Save minhphong306/caf81a32839a02cdd7f9a6aeb9899843 to your computer and use it in GitHub Desktop.
Loc nguyen to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function locNguyenTo(arr) { | |
const arrNguyenTo = []; | |
for (let i = 0;i < arr.length; i++) { | |
if (arr[i] === 0 || arr[i] === 1) { | |
continue; | |
} | |
let count = 0; | |
for (let j=2; j < arr[i]; j++) { | |
if (arr[i] % j === 0) { | |
count++; | |
} | |
} | |
if (count === 0) { | |
arrNguyenTo.push(arr[i]); | |
} | |
} | |
return arrNguyenTo; | |
} | |
const nguyenTo = locNguyenTo([1, 2, 3, 6, 0]); | |
console.log(nguyenTo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment