Scotch Falsy Bouncer (v5)

Revision 5 of this benchmark created by Carlos Matheu on


Setup

// USING A FOR OF LOOP
  
  function falsyBouncerForOf(array) {
      let result =[]
      
      for (value of array){
          if(value){
              result.push(value)
          }
      }
      
      return result
  }
  
  // USING .FILTER()
  
  function falsyBouncerFilter(array) {
      return array.filter((value) =>{
        return Boolean(value)  
      })
  }
  
  function falsyBouncerFilter2(array) {
        return array.filter(value => !!value);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using .filter() 2
falsyBouncerFilter2([NaN, 0, null, '', undefined])
ready
Using for
falsyBouncerFilter([NaN, 0, null, '', undefined])
ready
Using .filter()
falsyBouncerFilter([NaN, 0, null, '', undefined])
ready

Revisions

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

  • Revision 3: published by Carlos Matheu on
  • Revision 5: published by Carlos Matheu on