(text)
| 26 | loadData(); |
| 27 | |
| 28 | function textScript(text) { |
| 29 | let scripts = countBy(text, (char) => { |
| 30 | let script = characterScript(char.codePointAt(0)); |
| 31 | return script ? script.name : "none"; |
| 32 | }).filter(({ name }) => name != "none"); |
| 33 | |
| 34 | let total = scripts.reduce((n, { count }) => n + count, 0); |
| 35 | if (total == 0) return "No scripts found"; |
| 36 | |
| 37 | return scripts |
| 38 | .map(({ name, count }) => { |
| 39 | return `${Math.round((count * 100) / total)}% ${name}`; |
| 40 | }) |
| 41 | .join(","); |
| 42 | } |
| 43 | |
| 44 | function countBy(items, groupName) { |
| 45 | let counts = []; |
no test coverage detected