Prime Factors in JavaScript