Reverse Prime Number

Problem

Write a program that flips each natural number when N natural numbers are input and outputs the prime number if the reversed number is prime. For example, flipping 32 is 23, and 23 is a prime number. Then it outputs 23. If you flip 910, you have to number it as 19. Consecutive zeros from the first digit are ignored.

input

The number of natural numbers N (3<=N<=100) is given in the first line, and N natural numbers are given in the next line. The size of each natural number does not exceed 100,000.

9
32 55 62 20 250 370 200 30 100

output

Print the reversed prime number on the first line. The output order is output in the order entered.

23 2 73 2 3

Solution

convering array

function isPrime(n) {
	if (n <= 1) return false;
	for (let i = 2; i < n; i++) {
		if (n % i === 0) return false;
	}
	return true;
}

function solution(arr) {
	let answer = [];

	for (let x of arr) {
		const n = parseInt(x.toString().split('').reverse().join(''));
		if (isPrime(n)) answer.push(n);
	}

	return answer;
}

not converting array

function isPrime(num) {
	if (num === 1) return false;
	// sqrt 제곱근
	for (let i = 2; i <= parseInt(Math.sqrt(num)); i++) {
		if (num % i === 0) return false;
	}
	return true;
}

function solution(arr) {
	let answer = [];

	for (let x of arr) {
		let res = 0;
		while (x) {
			let t = x % 10;
			res = res * 10 + t;
			x = parseInt(x / 10);
		}

		if (isPrime(res)) answer.push(res);
	}

	return answer;
}