Hilbert curve 2d to 1d mapping in JS.