Skip to content

Instantly share code, notes, and snippets.

@pietro909
Last active October 28, 2016 08:33
Show Gist options
  • Save pietro909/587ff2336a92eb5357d0fd002349eaec to your computer and use it in GitHub Desktop.
Save pietro909/587ff2336a92eb5357d0fd002349eaec to your computer and use it in GitHub Desktop.
Example of how to handle unknown input
function contains(c, s) {
var index = typeof s === 'string' ? s.indexOf(c) : -1;
return index > -1;
}
console.log(contains("hi", "there")); // false
console.log(contains("hi", "hi, all")); // true
console.log(contains("hi", 1)); // false
console.log(contains("hi", null)); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment