Huffman coding in javascript