function solution(numbers) {
var num_array = numbers.split('');
var answer = 0;
var nums = new Set();
solution2(num_array,'');
function solution2(first, second) {
if (second.length > 0) {
if (nums.has(Number(second))=== false) {
nums.add(Number(second));
console.log(Number(second))
if (chkPrime(Number(second))) {
answer++;
}
}
}
if (first.length > 0) {
for (var i = 0; i< first.length; i++) {
var t = first.slice(0)
t.splice(i,1);
console.log(t,second + first[i]);
solution2(t,second + first[i]);
}
}
}
function chkPrime(num) {
if (num < 2) return false;
if (num === 2) return true;
for (var i = 2; i <= Math.sqrt(num); i++) {
if (num%i===0) return false;
}
return true;
}
return answer;
}
console.log(solution("123"))
설명이 너무 좋습니다. 감사합니다.!