Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // auto carring
  2. export const pluralization = (() => {
  3. 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];
  4. return (word, n) => {
  5. if (typeof n === 'undefined') return _n => self(word, _n);
  6. return self(word, n);
  7. };
  8. })();
  9.  
  10. // test:
  11. const apple = [ 'Яблоко', 'Яблока', 'Яблок'];
  12. [ ...Array(25).keys() ].forEach(i => console.log(`%c${i} ${pluralization(apple, i)}`, 'color: forestgreen'));
  13. const comment = pluralization([ 'Коментарий', 'Коментария', 'Комантариев' ]);
  14. [ ...Array(25).keys() ].forEach(i => console.log(`%c${i} ${comment(i)}`, 'color: chocolate'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement