Created
May 31, 2018 21:03
-
-
Save ilko725/728fdbaa2e4a4bbfe39b58054931e478 to your computer and use it in GitHub Desktop.
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
var numbers = [4, 6, 7, 8, 34, 54, 5, 3, 63, 76]; | |
function isPrime(num) { | |
for (var i = 2; i < num; i++) | |
if (num % i === 0) return false; | |
return num !== 1; | |
} | |
function isPrimeArray(anyArray) { | |
if (!anyArray.length) | |
return null | |
var resp = { | |
prime: [], | |
composite: [] | |
} | |
for (var n of anyArray) { | |
if (isPrime(n)) | |
resp.prime.push(n) | |
else | |
resp.composite.push(n) | |
} | |
return resp | |
} | |
function outputPrime(value) { | |
console.log(value) | |
} | |
function mskt3d(anyArray2, callback1, callback2) { | |
var isPr = isPrimeArray(anyArray2) | |
callback1(isPr.prime) | |
callback1(isPr.composite) | |
return isPr | |
} | |
mskt3d(numbers, outputPrime, outputPrime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment