Factoring Numbers

This code comes in two parts: The prime number generator, that generates the prime numbers and stores them into an array, and the factoring part which is way simpler.

:
var primes=new array(2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127);
/*Use some algorithm to create array (we are using this as a short cut). This works until 16255.
 *
 *Warning! This code may be inaccurate in syntax or may not work properly.
 *Please refrain from using it.
 */
function factorisenumber(primes,number)
{
var remainder=number;
for (factor=1; factor<math.sqrt; factor=primes.shift)
{
while (ceil(remainder/factor)==floor(remainder/factor))
{
document.write(factor+ "<br />");
remainder=remainder/factor
}
}
document.write("are the factors of" + number + ".")
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License