修复编码规则

master
yutent 2022-03-21 18:23:47 +08:00
parent 174d46d920
commit 27668f8fee
1 changed files with 15 additions and 1 deletions

View File

@ -35,13 +35,27 @@ export function createCode(dict, word) {
break
}
}
case 4: {
let c1 = dict.get(word[0])?.pop()
let c2 = dict.get(word[1])?.pop()
let c3 = dict.get(word[2])?.pop()
let c4 = dict.get(word[3])?.pop()
if (c1 && c2 && c3 && c4) {
return c1[0] + c2[0] + c3[0] + c4[0]
} else {
console.error(word, '词组中存在未收录单字, 请到github上提交issues')
break
}
}
default: {
let c1 = dict.get(word[0])?.pop()
let c2 = dict.get(word[1])?.pop()
let ce = dict.get(word[word.length - 1])?.pop()
if (c1 && c2 && ce) {
return c1.slice(0, 1) + c2.slice(0, 1) + ce.slice(0, 2)
return c1[0] + c2[0] + ce.slice(0, 2)
} else {
console.error(word, '词组中存在未收录单字, 请到github上提交issues')
break