Advertisement
Booster

Find Nth Digit

Oct 13th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findNthDigit(inArr) {
  2.     var number, reg,
  3.         nthDigit;
  4.     reg = RegExp(/\d/g);
  5.     number = inArr[1].toString().match(reg);
  6.     nthDigit = inArr[0];
  7.     if (nthDigit > number.length) {
  8.         return "The number doesn’t have" + nthDigit + " digits";
  9.     }
  10.     nthDigit = number[number.length - (nthDigit)];
  11.     return nthDigit;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement