Prime Factor And Javascript
I'm stuck with the JavaScript code I am using for solving a problem which states: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number
Solution 1:
Your issue isn't a mathematical one -- you just have a bug in one of your conditional checks.
Change if(b = n-1)
to if(b == n-1)
. Right now, your code isn't actually checking to ensure that a factor is prime; instead, it's assigning the value of n-1
to b
(for odd values of n
) and then automatically calling a1(b
), so your result is all possible odd factors of k
.
Post a Comment for "Prime Factor And Javascript"