mgechev / javascript-algorithms

💻 JavaScript implementations of computer science algorithms
https://mgechev.github.io/javascript-algorithms/
MIT License
7.83k stars 1.27k forks source link

Code issue in LZW.js ? #148

Closed rthangam closed 5 years ago

rthangam commented 5 years ago

I see this file has exports.LZW.compress and exports.LZW.decompress methods which are not prototypes? Ideally it should have been defined asexports.LZW.prototype.compress and exports.LZW.prototype.decompress ?

Also decompress won't return back the compressed data ?

var lzw = new LZW(); undefined var compressed = lzw.compress("ABCABCABCABCABCABC"); undefined compressed (9) [65, 66, 67, 256, 258, 257, 259, 262, 257] var decompress = lzw.decompress(compressed); undefined decompress "ABCĀĂāăĆā"

mgechev commented 5 years ago

Since LZW doesn't hold any state and we don't instantiate any objects we don't need to add the methods to the prototype.

rthangam commented 5 years ago

Thanks