Created
February 18, 2018 06:51
-
-
Save crshmk/79cc8cac838305f7ab3db88a469e6484 to your computer and use it in GitHub Desktop.
Empty test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* empty array | |
* empty string | |
* function of zero arity | |
* empty object | |
* null | |
* undefined | |
*/ | |
var empty = x => Array.isArray(x) || typeof x === 'string' || typeof x === 'function' ? | |
!x.length : null == x || Object.keys(x).length === 0 && x.constructor === Object | |
/** | |
* also test for 0 | |
*/ | |
var empty = x => Array.isArray(x) || typeof x === 'string' || typeof x === 'function' ? !x.length : | |
typeof x === 'number' ? x === 0 : | |
null == x || Object.keys(x).length === 0 && x.constructor === Object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment