Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Eliminate falsy values in an array
(version: 0)
Comparing performance of:
Using Boolean constructor vs Using !!x Expression vs Using x => x vs Using Boolean constructor with lodash
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr = [0, 1, '', undefined, false, 2, undefined, null, , 3, NaN];
Tests:
Using Boolean constructor
var result = arr.filter(Boolean);
Using !!x Expression
var result = arr.filter(x => !!x);
Using x => x
var filtered = arr.filter(x => x);
Using Boolean constructor with lodash
var filtered = _.filter(arr, Boolean);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Using Boolean constructor
Using !!x Expression
Using x => x
Using Boolean constructor with lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
lodash vs es6 in every method
empty arr
without vs filter
Array.filter vs lodash.compact
Comments
Confirm delete:
Do you really want to delete benchmark?