Advertisement
Anatolyukropov

Правильное склонение по-русски: «год», «года», «лет» в JavaScript

Aug 13th, 2021 (edited)
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. <script>
  2. function yearDeclension(number, titles) { // склонение именительных рядом с числительным
  3. cases = [2, 0, 1, 1, 1, 2];
  4. return number+" "+titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
  5. }
  6. console.log( yearDeclension(18, ['год', 'года', 'лет']) );
  7. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement