작성
·
173
1
function psearch(n) {
let p = 1;
while (p * p <= n) {
p += 1;
}
return p;
}
function solution(num) {
let answer = [];
for (let i = 0; i < num.length; i++) {
let now = parseInt(num[i].toString().split("").reverse().join(""));
if (now === 2) {
answer.push(now);
} else if (now === 1) {
continue;
} else {
let p = psearch(now);
let val = 0;
for (let j = 2; j <= p; j++) {
if (now % j === 0) {
val += 1;
}
}
if (val === 0) {
answer.push(now);
}
}
}
return answer;
}
let arr = [32, 55, 62, 20, 250, 370, 200, 30, 100, 5, 7, 6];
console.log(solution(arr));