Skip to content

Instantly share code, notes, and snippets.

@andrejsharapov
Created June 20, 2024 08:06
Show Gist options
  • Save andrejsharapov/0bae76e99c135ac29e589a9f14e814df to your computer and use it in GitHub Desktop.
Save andrejsharapov/0bae76e99c135ac29e589a9f14e814df to your computer and use it in GitHub Desktop.
Склонение слов
<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