... read the whole story at 30secondsofcode.org.
Returns the array of factors of the given
num. If the second argument is set to
true returns only the prime factors of
0 returns an empty array. If
num is less than
0 returns all the factors of
-int together with their additive inverses.
Array.filter() to find all the factors of
num. If given
num is negative, use
Array.reduce() to add the additive inverses to the array. Return all results if
false, else determine and return only the prime factors using
Array.filter(). Omit the second argument,
primes, to return prime and non-prime factors by default.