Last active
April 28, 2018 08:43
-
-
Save flodolo/1d205d777f4f85a686f082ab250f2a8b to your computer and use it in GitHub Desktop.
Test Cornish plurals
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
/* | |
[zero 0] | |
0 | |
[one 1] | |
1 | |
[two 2] | |
2 and all numbers that end in 02, 22, 42, 62 and 82; | |
numbers that end with the following multiples of 1,000: 1,000-20,000, 40,000, 60,000, | |
80,000; numbers that end with a multiple of 100,000 | |
[few 3] | |
3 and all numbers that end in 03, 23, 43, 63 and 83 | |
[many 4] | |
all numbers that end in 01, 21, 41, 61 and 81 | |
[other 5] | |
other: all other numbers | |
*/ | |
plural = function (n) { | |
return (n==0) | |
? 0 | |
: (n==1) | |
? 1 | |
: ((n%100==2 || n%100==22 || n%100==42 || n%100==62 || n%100==82) || ((n%1000==0 && n%100000>=1000 && n%100000<=20000) || (n%20000==0) && n%1000000!=0)) | |
? 2 | |
: (n%100==3 || n%100==23 || n%100==43 || n%100==63 || n%100==83) | |
? 3 | |
: (n%100==1 || n%100==21 || n%100==41 || n%100==61 || n%100==81) | |
? 4 | |
: 5; | |
} | |
/* Compact version for Pontoon | |
(n==0)?0:(n==1)?1:((n%100==2||n%100==22||n%100==42||n%100==62||n%100==82)||((n%1000==0&&n%100000>=1000&&n%100000<=20000)||(n%20000==0)&&n%1000000!=0))?2:(n%100==3||n%100==23||n%100==43||n%100==63||n%100==83)?3:(n%100==1||n%100==21||n%100==41||n%100==61||n%100==81)?4:5 | |
*/ | |
let output = 'Numbers from 0 to 99:\n'; | |
for (let i = 0; i < 200; i++) { | |
if (i!=0 && i%10==0) { | |
output += '\n'; | |
} | |
output += plural(i) + ','; | |
if (i==99) { | |
output += '\n\nNumbers from 100 to 199:'; | |
} | |
} | |
output += '\n\nSpecial cases:\n'; | |
special_cases = [ | |
1000, 1435, 5000, 10000, 20000, 21000, 30000, 40000, 60000, 80000, 90000, | |
100000, 110000, 115000, 130000, 140000, 150000, 180000, 208000, | |
800000, 820000, 1100000, 56500000, 1000000, 1005000, 10000000, 1000000000, | |
] | |
for (let i of special_cases) { | |
let n = i.toLocaleString(undefined) | |
output += `${n}: ${plural(i)}\n`; | |
} | |
console.log(output); |
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
Numbers from 0 to 99: | |
0,1,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
Numbers from 100 to 199: | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
5,4,2,3,5,5,5,5,5,5, | |
5,5,5,5,5,5,5,5,5,5, | |
Special cases: | |
1,000: 2 | |
1,435: 5 | |
5,000: 2 | |
10,000: 2 | |
20,000: 2 | |
21,000: 5 | |
30,000: 5 | |
40,000: 2 | |
60,000: 2 | |
80,000: 2 | |
90,000: 5 | |
100,000: 2 | |
110,000: 2 | |
115,000: 2 | |
130,000: 5 | |
140,000: 2 | |
150,000: 5 | |
180,000: 2 | |
208,000: 2 | |
800,000: 2 | |
820,000: 2 | |
1,100,000: 2 | |
56,500,000: 2 | |
1,000,000: 5 | |
1,005,000: 2 | |
10,000,000: 5 | |
1,000,000,000: 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment