Skip to content

Instantly share code, notes, and snippets.

@jondashkyle
Last active April 8, 2021 15:24
Show Gist options
  • Save jondashkyle/b9330641247b9bd67669445865c44a40 to your computer and use it in GitHub Desktop.
Save jondashkyle/b9330641247b9bd67669445865c44a40 to your computer and use it in GitHub Desktop.
Switch it up
// Pseudo-code of a pattern I use frequently.
const theTitle = 'Seeing is forgetting the name of the thing one sees'
const isActive = true
const duration = 420
switch (true) {
case !!theTitle:
return 'Has a title!'
case isActive && duration > 300:
return 'Active with medium duration'
case !!theTitle && !isActive:
case duration < 100 && !isActive:
return 'Has a title, but not active, or short and active'
default:
return 'Whatever!'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment