Last active
December 29, 2018 16:32
-
-
Save zmnv/24b27fd1156b58be8bf5265e1f38e53a to your computer and use it in GitHub Desktop.
Cute Numbers with spaces. Cyrillic labels by last number.
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
function cuteNumber(num) { | |
num = ''+num; | |
return num.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');; | |
} | |
function cuteNumberObjects(num, replacer = ['объект', 'объекта', 'объектов']) { | |
num = cuteNumber(num); | |
switch(num[num.length - 1]) { | |
case '1': | |
return `${num} ${replacer[0]}`; | |
case '2' || '3' || '4': | |
return `${num} ${replacer[1]}`; | |
case '0' || '5' || '6' || '7' || '8' || '9': | |
return `${num} ${replacer[2]}`; | |
} | |
} | |
console.log(cuteNumberObjects(5421, ['картинка', 'картинки', 'картинок'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment