Project Euler #41 - pandigital prime
I think this is a bit over engineered. Let's talk our way through the problem.


By definition we know the highest pandigital number is 987654321.
We need to loop through each odd number between 1 and 987654321.
We need to test each number as a prime.
Here's a nice optimised isPrime function from here.

function isPrime(number) {
  var start = 2;
  while (start &lt;= Math.sqrt(number)) {
    if (number % start++ &lt; 1) return false;
  }
  return number &gt; 1;
}

If it is prime we need to test each number is pandigital. We should only need to loop once. If we make a set of the digits in a number, then the length of the set will be equal to the total count of digits in the number.

function isPandigital(number) {
   var numStr = number.toString(),
     digits = [];

   for (var digit in numStr) {

     if (numStr.hasOwnProperty(digit) &amp;&amp; digits.indexOf(digit) === -1) 
        digits.push(digit);
   }

   return digits.length === numStr.length;
}

Then you just need to write the loop:

var pandigitalPrimes = [];

for (var n = 1; n &lt;= 987654321; n+=2) {
  if (isPrime(n) &amp;&amp; isPandigital(n)) pandigitalPrimes.push(n);
}

Now it's your job to optimise these ideas so that this process doesn't take absolutely forever.