🏠 Games Tutorials Dev blog JS code golf Other projects

Mini Burrows Wheeler

October 2017

Burrows-wheeler transform/untransform functions in less than 128b (golfed during #golfctober 2017)

(The character "ÿ" is used by both functions as the end of line delimiter)

This transformation is often used in data compression.

- Github

- Demo: transform / untransform

// Transform
s=>[...s+='ÿ'].map((_,i)=>s[S='slice'](i)+s[S](0,i)).sort().map(x=>x[S](-1)).join``

// Untransform
(d,t=d.indexOf`ÿ`)=>[...[...d].keys()].sort((x,y)=>d[a='charCodeAt'](x)-d[a](y)||x-y).map((m,_,i)=>d[t=i[t]]).join``.slice(0,-1)