Cause of the problem:
Preparatory work:
1. Need a binary tree data structure JS version, I would like to use an array representation, as follows
The Var arr=[];//holds the corresponding characters
Character $=>arr[0],$0=>arr[1],$1=>arr[2],$00=>arr[3],$01=>arr[4],$10=>arr[5],$11=>arr[6],
Summing up the rules above, what I need to do is to convert a binary number into 10 binary
function trans (strnum) {
if (arguments.length==0) {return 0;}
var num=0;
for (Var i=0;i<strnum.length;i++) {
Num+=math.pow (2,+strnum[i]+strnum.length-i-1)
}
return num;
}
Trans () =>0,trans ("0") =>1,trans ("1") =>2,trans ("xx") =>3,trans ("") =>4,trans ("Ten") =>5,trans (" One ") =>6
2. Decode the encrypted character and convert the corresponding encoding to the corresponding character
The Var arr=[];//holds the corresponding characters
var newstr=str.replace (/\$ (\d*)/g,function (M,P1) {
Return Arr[trans (p1)];
})
Newstr is the decoded character.
Not to be continued!
JS version of the article encryption compression algorithm Holman encoding