From 54790b32355542b768ee75bf8407cca5f6485b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Tue, 26 Sep 2017 12:53:53 +0800 Subject: [PATCH] Removed rudundant conditionals --- date.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/date.js b/date.js index ff9a95b..54ac1eb 100644 --- a/date.js +++ b/date.js @@ -11,12 +11,12 @@ var DAY = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "S var getOrdinalSuffix = function(day) { - if (day < 4 || ( 20 < day && day < 24 )) { - if (day == 1 || day == 21) return "st"; - else if (day == 2 || day == 22) return "nd"; - else if (day == 3 || day == 23) return "rd"; - } - else if (day == 31) return "st"; + if( day < 1 || 31 < day ) + throw new Error( "Day is out of range 1 <= day <= 31" ); + + if ( day == 1 || day == 21 || day == 31 ) return "st"; + else if ( day == 2 || day == 22 ) return "nd"; + else if ( day == 3 || day == 23 ) return "rd"; return "th"; };