Commit 909a1bf 1 parent be6e25b commit 909a1bf Copy full SHA for 909a1bf
File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ var toOrdinal = typeof require !== 'undefined' ? require('../src/toOrdinal') : w
4
4
5
5
describe ( 'toOrdinal' , function ( ) {
6
6
var tests = [
7
+ { input : - 121 , expect : '-121st' } ,
8
+ { input : - 13 , expect : '-13th' } ,
9
+ { input : - 12 , expect : '-12th' } ,
10
+ { input : - 11 , expect : '-11th' } ,
11
+ { input : - 3 , expect : '-3rd' } ,
12
+ { input : - 2 , expect : '-2nd' } ,
7
13
{ input : - 1 , expect : '-1st' } ,
8
14
{ input : 0 , expect : '0th' } ,
9
15
{ input : 1 , expect : '1st' } ,
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ function toOrdinal(number) {
13
13
var num = parseInt ( number , 10 ) ;
14
14
if ( ! isFinite ( num ) ) throw new TypeError ( 'Not a finite number: ' + number + ' (' + typeof number + ')' ) ;
15
15
var str = String ( num ) ;
16
- var lastTwoDigits = num % 100 ;
16
+ var lastTwoDigits = Math . abs ( num % 100 ) ;
17
17
var betweenElevenAndThirteen = lastTwoDigits >= 11 && lastTwoDigits <= 13 ;
18
18
var lastChar = str . charAt ( str . length - 1 ) ;
19
19
return str + ( betweenElevenAndThirteen ? 'th'
You can’t perform that action at this time.
0 commit comments