Advertisement
Viktor_Profa

Codewars

Aug 8th, 2022 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function whatCentury(year)
  2. {
  3.   let g
  4.   let num
  5.   let array = []
  6.   let result
  7.  
  8.   let number =[]
  9.   let x = array[0] + array[1] +array[2] +array[3]
  10.   let y = array[0] + array[1]
  11.   for(let x = 0; x < year.length; x++){
  12.     g  = parseInt(year[x])
  13.     array.push(g)
  14.   }
  15.   if (x == y){
  16.     number[0] =  year[0]
  17.     number[1] = year[1]
  18.     num = number[0] + number [1]
  19.    
  20.   }else{
  21.    
  22.     number[0] =  year[0]
  23.     number[1] = year[1]
  24.     num = year[0] + year[1]
  25.     num = parseInt (num)
  26.     num = num + 1
  27.    
  28.     number[0] = parseInt(number[0])
  29.     number[1] = parseInt(number[1])
  30.   }
  31.  
  32.  
  33.   let letter
  34.   if(num< 21){
  35.     letter = "th"
  36.  
  37.   }
  38.  
  39.   if (num > 20){
  40.     if (number[1] == 1){
  41.       letter = "st"
  42.     }
  43.     if (number[1] == 2){
  44.       letter = "nd"
  45.     }
  46.     if(number[1] == 3){
  47.       letter = "rd"
  48.     }
  49.   }
  50.  
  51.   result = num + letter
  52.   return result
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. /*Возвращает век введенного года. Ввод всегда будет строкой из 4 цифр, поэтому проверка не требуется.
  62.  
  63. Примеры
  64. "1999" --> "20th"
  65. "2011" --> "21st"
  66. "2154" --> "22nd"
  67. "2259" --> "23rd"
  68. "1124" --> "12th"
  69. "2000" --> "20th"
  70. */
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement