Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created October 20, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobias/f7ec650ec29ebd26e2ee06144e61d5c1 to your computer and use it in GitHub Desktop.
Save zerobias/f7ec650ec29ebd26e2ee06144e61d5c1 to your computer and use it in GitHub Desktop.
How to filter really empty data
var isEmpty = (a, b, c) => {
return ![a, b, c].join("");
}
var isEmpty = (...rest) => {
return !rest.join("");
}
isEmpty(void 0, [], null) // => true
isEmpty(void 0, [], null, 0) // => false
isEmpty(void 0, [], null, {}) // => false. С пустым объектом такой трюк не проходит
// Или так, в случае если аргумент один
var isEmpty = (arg) => {
return !([arg] + "");
}
isEmpty(null) // => true
isEmpty(void 0) // => true
isEmpty(0) // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment