Created
May 6, 2019 15:17
-
-
Save mistercoffee66/93fdd1be5dc981c799796c8d9f0de623 to your computer and use it in GitHub Desktop.
opinionated test for truthy
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
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