Created
July 30, 2019 06:45
-
-
Save edi/7d8354a81b2c233e559ec8013ef462e4 to your computer and use it in GitHub Desktop.
successor method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function successor(prefix) { | |
let limit = prefix; | |
while ( limit.length > 0 ) { | |
const index = limit.length - 1; | |
if ( limit[index] === '\xff' ) | |
limit = limit.slice(0, -1) | |
else { | |
limit = limit.substr(0, index) + String.fromCharCode(limit.charCodeAt(index) + 1) | |
break | |
} | |
} | |
return limit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment