var util = require('util');
var validator = require('validator');

function Nth()
{
	var that = this;
	that.getLastDigit = function(number)
	{
		var numberAsString = number.toString();
		var lastDigit = numberAsString[numberAsString.length - 1];
		return lastDigit;
	};

	return {
		appendSuffix: function(number)
		{
			if (validator.isInt(number) != true)
			{
				throw new 'Oh no';
			}

			if (number > 3 && number < 21) {
				return util.format('%sth', number);
			}

			var lastDigit = that.getLastDigit(number);

			if (lastDigit == '1') {
				return util.format('%sst', number);
			} else if (lastDigit == '2') {
				return util.format('%snd', number);
			} else if (lastDigit == '3') {
				return util.format('%srd', number);
			} else {
				return util.format('%sth', number);
			}
		}
	};
}

module.exports = new Nth();
@@ -64,223 +64,27 @@
 );%0A%0A
-function Nth()%0A%7B%0A%09var that = this;%0A%09that.getLastDigit = function(number)%0A%09%7B%0A%09%09var numberAsString = number.toString();%0A%09%09var lastDigit = numberAsString%5BnumberAsString.length - 1%5D;%0A%09%09return lastDigit;%0A%09%7D;%0A%0A%09return
+module.exports =
  %7B%0A
-%09
 %09app
@@ -114,14 +114,10 @@
 ber)
-%0A%09%09
 %7B%0A
-%09
 %09%09if
@@ -157,12 +157,10 @@
 )%0A%09%09
-%09
 %7B%0A
-%09
 %09%09%09t
@@ -183,49 +183,119 @@
 ;%0A%09%09
-%09
 %7D%0A%0A%09%09
-%09if (number %3E 3
+var digits = Math.abs(number).toString().split('').reverse();%0A%0A%09%09if(digits.length %3E 1
  && 
-number %3C 2
+digits%5B1%5D == 
 1)
- 
 %7B%0A
-%09
 %09%09%09r
@@ -335,84 +335,36 @@
 ;%0A%09%09
-%09%7D%0A%0A%09%09%09var lastDigit = that.getLastDigit(number);%0A%0A%09%09%09if (lastDigit == '1') 
+%7Delse%7B%0A%09%09%09if(digits%5B0%5D == 1)
 %7B%0A%09%09
@@ -409,36 +409,31 @@
 %09%09%09%7D
- 
 else if
- (lastDigit == '2') 
+(digits%5B0%5D == 2)
 %7B%0A%09%09
@@ -478,36 +478,31 @@
 %09%09%09%7D
- 
 else if
- (lastDigit == '3') 
+(digits%5B0%5D == 3)
 %7B%0A%09%09
@@ -547,14 +547,12 @@
 %09%09%09%7D
- 
 else
- 
 %7B%0A%09%09
@@ -604,36 +604,8 @@
 %7D%0A%09%7D
+%0A%7D
 ;%0A
-%7D%0A%0Amodule.exports = new Nth();

Fixed wrong values: 111 => 111th 112 => 112th 113 => 113th