Created
November 1, 2019 21:27
-
-
Save scottcame/764cf710156f4c017053f475e8fa30c3 to your computer and use it in GitHub Desktop.
This file contains 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
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