complete javascript version of maximizingXor