Skip to content

Instantly share code, notes, and snippets.

@JoeCortopassi
Created October 15, 2018 23:57
Show Gist options
  • Save JoeCortopassi/7fe5f707f3000c959b4ce57221f93a37 to your computer and use it in GitHub Desktop.
Save JoeCortopassi/7fe5f707f3000c959b4ce57221f93a37 to your computer and use it in GitHub Desktop.
function isValidIP(str) {
return str
.split('.')
.filter(numPredicate)
.filter(rangePredicate)
.length === 4;
}
let numPredicate = num => (parseInt(num, 10) + '') === num;
let rangePredicate = num => parseInt(num, 10) >= 0 && parseInt(num, 10) <= 255;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment