Skip to content

Instantly share code, notes, and snippets.

@alexko30
Created April 30, 2018 22:43
Show Gist options
  • Save alexko30/66889b5bc4f44cf39122d8b5d4653466 to your computer and use it in GitHub Desktop.
Save alexko30/66889b5bc4f44cf39122d8b5d4653466 to your computer and use it in GitHub Desktop.
find Digit
function findDigit(number, nth) {
if(nth <= 0) {
console.log(-1);
} else {
const digits = (""+number).split("");
const digitLength = digits.length;
const ourNumIndex = digitLength - nth;
console.log(digits[ourNumIndex]);
}
}
findDigit(123456789, 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment