Last active
April 9, 2016 10:12
-
-
Save c01nd01r/b97e4a353390f0cc3dc5 to your computer and use it in GitHub Desktop.
Просто числа / BasicQual#5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findPrime(array) { | |
if (Array.isArray(array)) { | |
for (var number = 2; number <= 99991; number++) { | |
if (isContains(number, array) && isPrime(number)) { | |
return number; | |
} | |
} | |
} else { | |
console.log(array + ' is not array!'); | |
return false; | |
} | |
//Проверка на Простое число | |
function isPrime(n) { | |
if (n === 1) return false; | |
for (var d = 2; d * d <= n; d++) { | |
if (n % d === 0) | |
return false; | |
} | |
return true; | |
} | |
//Проверка на совпадение всех цифр из проверочного массива | |
function isContains(number, array) { | |
var numberArray = String(number).split(''); | |
return numberArray.every(function(elem) { | |
return array.indexOf(+elem) != -1; | |
}) && array.every(function(elem) { | |
return numberArray.indexOf('' + elem) != -1; | |
}); | |
} | |
return false; | |
} | |
console.log(findPrime([3, 1])); | |
// 13 | |
console.log(findPrime([2, 8])); | |
// false | |
console.log(findPrime([4, 9])); | |
// 449 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment