Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // auto carring
- export const pluralization = (() => {
- const self = (word, n) => word[n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2];
- return (word, n) => {
- if (typeof n === 'undefined') return _n => self(word, _n);
- return self(word, n);
- };
- })();
- // test:
- const apple = [ 'Яблоко', 'Яблока', 'Яблок'];
- [ ...Array(25).keys() ].forEach(i => console.log(`%c${i} ${pluralization(apple, i)}`, 'color: forestgreen'));
- const comment = pluralization([ 'Коментарий', 'Коментария', 'Комантариев' ]);
- [ ...Array(25).keys() ].forEach(i => console.log(`%c${i} ${comment(i)}`, 'color: chocolate'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement