Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created April 17, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/316b38f1288bfd710a9cb74f92a45c34 to your computer and use it in GitHub Desktop.
Save Nicknyr/316b38f1288bfd710a9cb74f92a45c34 to your computer and use it in GitHub Desktop.
CodeSignal - Character Parity
/*
Given a character, check if it represents an odd digit, an even digit or not a digit at all.
Example
For symbol = '5', the output should be
characterParity(symbol) = "odd";
For symbol = '8', the output should be
characterParity(symbol) = "even";
For symbol = 'q', the output should be
characterParity(symbol) = "not a digit".
*/
function characterParity(symbol) {
// Turn the string into a number
let num = parseInt(symbol, 10);
// If num is not a number it's a letter
if(isNaN(num)) {
return "not a digit";
}
else {
if(num % 2 === 0) {
return "even";
}
else {
return "odd";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment