Skip to content

Instantly share code, notes, and snippets.

@ilko725
Created May 31, 2018 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilko725/728fdbaa2e4a4bbfe39b58054931e478 to your computer and use it in GitHub Desktop.
Save ilko725/728fdbaa2e4a4bbfe39b58054931e478 to your computer and use it in GitHub Desktop.
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