this is a helper function, along with three other’s it should be called as a .filter(); to return only prime numbers. It is for one of the exercises at FreeCodeCamp.com, Sum all Primes.
I’m just trying to accumulate the charAt(*) for each n,
so 10 would return 1, being 1+0
and 977 would return 23, being 9+7+7
I’ve commented out some of my attempts before thinking of charAt(0) and some n’s will have as many as four digits, maybe more if I don’t have to limit it, but the largest test case stops in the thousands. 997 I think, but an extra decimal for margin of error.
function isItTHREED(n) {
// https://www.thoughtco.com/how-to-determine-number-is-prime-2312518
// Try 3. Take the number, and add the digits up, when those digits are divisible by 3, the number is not prime.
// Take 2469, those digits add up to 21, and 21 is divisible by 3, therefore 2469 is not a prime number.
console.log('3s',n);
/*
n = n.toString();
n = n.split('');
//num = num.split('');
n = [n];
console.log("num", n);
*/
return n;
} //end of isItTHREED
isItTHREED(10); // should return 1
isItTHREED(977); // should return 23.