Created
October 21, 2019 23:50
-
-
Save alacret/6adb8aabb11946c9de0ae2b252886db5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const getDivisors = (num) => { | |
const divisors = [1]; | |
for (let i = 2; i <= num; i++) | |
if (num % i === 0 ) | |
divisors.push(i) | |
return divisors; | |
} | |
function procArrInt(listNum) { | |
let primeCounter = 0; | |
let maxDivisors = 0; | |
let maximumMembers = []; | |
for (let i = 0, j = listNum.length; i <= j; i++){ | |
const divisors = getDivisors(listNum[i]); | |
if (divisors.length === 2 ) | |
primeCounter++; | |
if (divisors.length > maxDivisors){ | |
maxDivisors = divisors.length; | |
maximumMembers = [listNum[i]]; | |
continue; | |
} | |
if (divisors.length === maxDivisors){ | |
maximumMembers.push(listNum[i]); | |
continue; | |
} | |
} | |
return [listNum.length,primeCounter, [maxDivisors,maximumMembers.sort((a,b) => a-b)] ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment