Uniq

Benchmark created by alk on


Preparation HTML

<script>
  var array = [0, 1, 20, 5, 6, 20, 3, 0, 2, 5, 0, 5, 2, 23, 0, 2, 0, 12, 3, 2, 0, 255];
    function uniqFor(array) {
      var i, j;
      array = array.slice();
      for (i = 0; i < array.length; i += 1) {
        for (j = i + 1; j < array.length; j += 1) {
          if (array[i] === array[j]) {
            array.splice(j, 1);
            j -= 1;
          }
        }
      }
      return array;
    }
    
    function uniqFilter(array) {
      return array.filter(function(value, i) {
        return array.indexOf(value, i + 1) === -1;
      });
    }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
For
uniqFor(array);
ready
Filter
uniqFilter(array);
ready

Revisions

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