6 ms·
The author used `-` as the sorting character for negatives instead of `!` as stated in the article. If you change his functions to use `!` for encoding negativ
by rockostrich 9y ago
The author used `-` as the sorting character for negatives instead of `!` as stated in the article. If you change his functions to use `!` for encoding negatives then it correctly sorts.
function encodeLong(s) {
if (s[0] !== '-') { return encodeNonNegative(s, ' '); }
return '!' + translate(encodeNonNegative(s.slice(1), ' '));
}
function decodeLong(s) {
if (s[0] !== "!") { return decodeNonNegative(s); }
return '-' + decodeNonNegative(translate(s.slice(1)));
}