Thursday, 19 April 2012

Finding the numbers that a number is divisible by...

I'm no Math geek (Hi Dr G!) but I needed to figure out all the numbers that a particular number was divisible by so that I could scale it without having to rely on The Gimps algorithms to smooth it so I wrote the following script:

  var num = 15;
  for(var n = 1; n < (num / 2); n++){
    var res = num / n;
    if (res === Math.round(res)){
      document.write("<p>" + res + "</p>");
Works a treat, just add your number as num variable and run in the browser

No comments:

Post a Comment