From 960fa239bcb1d91976643d899abcd4b424866b7d Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 10:15:43 +0200 Subject: [PATCH] Update get-ordinal-suffix-of-number.md --- snippets/get-ordinal-suffix-of-number.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/snippets/get-ordinal-suffix-of-number.md b/snippets/get-ordinal-suffix-of-number.md index 725ff05b4..f8832638b 100644 --- a/snippets/get-ordinal-suffix-of-number.md +++ b/snippets/get-ordinal-suffix-of-number.md @@ -5,14 +5,11 @@ Find which ordinal pattern digits match. If digit is found in teens pattern, use teens ordinal. ```js -const toOrdinalSuffix = int => { - int = parseInt(int); - var digits = [ (int % 10), (int % 100)]; - var ordinals = ["st", "nd", "rd", "th"]; - var oPattern = [1,2,3,4]; - var tPattern = [11, 12, 13, 14, 15, 16, 17, 18, 19] - - return oPattern.includes(digits[0]) && !tPattern.includes(digits[1]) ? int + ordinals[digits[0]-1] : int + ordinals[3]; +const toOrdinalSuffix = num => { + const int = parseInt(num), digits = [(int % 10), (int % 100)], + ordinals = ["st", "nd", "rd", "th"], oPattern = [1,2,3,4], + tPattern = [11, 12, 13, 14, 15, 16, 17, 18, 19] + return oPattern.includes(digits[0]) && !tPattern.includes(digits[1]) ? int + ordinals[digits[0]-1] : int + ordinals[3]; } // toOrdinalSuffix("123") -> "123rd" -``` \ No newline at end of file +```