Skip to content

Instantly share code, notes, and snippets.

@scottcame
Created November 1, 2019 21:27
Show Gist options
  • Save scottcame/764cf710156f4c017053f475e8fa30c3 to your computer and use it in GitHub Desktop.
Save scottcame/764cf710156f4c017053f475e8fa30c3 to your computer and use it in GitHub Desktop.
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Please enter a number: ', value => {
if (!(/[\-0-9]+/.test(value))) {
console.log("That's not a number. I said enter a number.")
process.exit(1);
}
let lengthWithNull = function(x) {
return x ? x.length : 0;
}
var odds = lengthWithNull(value.match(/[13579]/g));
var evens = lengthWithNull(value.match(/[2468]/g));
var zeros = lengthWithNull(value.match(/[0]/g));
console.log("Evens: " + evens);
console.log("Odds: " + odds);
console.log("Zeros: " + zeros);
rl.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment