Skip to content

Instantly share code, notes, and snippets.

@crshmk
Created February 18, 2018 06:51
Show Gist options
  • Save crshmk/79cc8cac838305f7ab3db88a469e6484 to your computer and use it in GitHub Desktop.
Save crshmk/79cc8cac838305f7ab3db88a469e6484 to your computer and use it in GitHub Desktop.
Empty test
/**
* 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