7-elephant

P39

Apr 29th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // In Firefox, press Ctrl+Shift+K then copy, paste and run.
  2.  
  3. function extractNum(num)
  4. {
  5.     var output = "";
  6.    
  7.     var length = 0;
  8.     var numTmp = num;
  9.     while(numTmp >= 1)
  10.     {
  11.         length++;
  12.         numTmp /= 10;
  13.     }
  14.    
  15.     for(var i = length-1; i >= 0; i--)
  16.     {
  17.         var ten = Math.pow(10,i);
  18.         var cur = Math.floor(num / ten) % 10;
  19.         if(cur > 0)
  20.         {
  21.             output += (i < length-1 ? "+" : "")
  22.                 + cur + (i > 0 ? "x" + ten : "");
  23.         }
  24.     }
  25.    
  26.     return output;
  27. }
  28.  
  29. extractNum(102034);
Advertisement
Add Comment
Please, Sign In to add comment