Skip to content

Instantly share code, notes, and snippets.

@mistercoffee66
Created May 6, 2019 15:17
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 mistercoffee66/93fdd1be5dc981c799796c8d9f0de623 to your computer and use it in GitHub Desktop.
Save mistercoffee66/93fdd1be5dc981c799796c8d9f0de623 to your computer and use it in GitHub Desktop.
opinionated test for truthy
const isTruthy = (expression) => {
if (typeOf expression === 'number') return true // 0 returns true
if (Array.isArray(expression) && expression.length < 1) return false // empty array returns false
if typeOf expression === 'Object' && Object.keys(expression).length < 1) return false // empty object returns false
return !!expression
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment