Huffman encoding in javascript and python