Created
June 20, 2024 08:06
-
-
Save andrejsharapov/0bae76e99c135ac29e589a9f14e814df to your computer and use it in GitHub Desktop.
Склонение слов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
{{ | |
getNoun(YourCount, | |
'комментарий', | |
'комментария', | |
'комментариев' | |
) | |
}} | |
</template> | |
<script> | |
export default { | |
methods: { | |
getNoun(number, one, two, five) { | |
let n = Math.abs(number); | |
n %= 100; | |
function name(n) { | |
if (n >= 5 && n <= 20) { | |
return five; | |
} | |
n %= 10; | |
if (n === 1) { | |
return one; | |
} | |
if (n >= 2 && n <= 4) { | |
return two; | |
} | |
return five; | |
} | |
return number + ' ' + name(n); | |
}, | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment