Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Last active May 19, 2024 15:42
Show Gist options
  • Save minhphong306/caf81a32839a02cdd7f9a6aeb9899843 to your computer and use it in GitHub Desktop.
Save minhphong306/caf81a32839a02cdd7f9a6aeb9899843 to your computer and use it in GitHub Desktop.
Loc nguyen to
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