fork download
  1. function myround(x) {
  2. var factor = Math.pow(10, Math.floor(Math.log(x)/Math.log(10)));
  3. return Math.ceil(x/factor)*factor;
  4. }
  5.  
  6. var nums = [15, 345, 201, 180, 93, 22];
  7. nums.forEach(function(x){print(x + " => " + myround(x));});
  8.  
Success #stdin #stdout 0.01s 4940KB
stdin
Standard input is empty
stdout
15 => 20
345 => 400
201 => 300
180 => 200
93 => 100
22 => 30