Zero Filled Functions

JavaScript performance comparison

Test case created by Mauricio Palma

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Mauricio Palma zeroFill
const zeroFill = (length, n) => new Array(length - n.toString().length ).fill(0).join('') + n;

const result = zeroFill(50, 25);
pending…
Stack Overflow zeroFill
function zeroFill( number, width )
{
  width -= number.toString().length;
  if ( width > 0 )
  {
    return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
  }
  return number + ""; // always return a string
}

var result = zeroFill(25, 50)
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments