Skip to content

Instantly share code, notes, and snippets.

@edi
Created July 30, 2019 06:45
Show Gist options
  • Save edi/7d8354a81b2c233e559ec8013ef462e4 to your computer and use it in GitHub Desktop.
Save edi/7d8354a81b2c233e559ec8013ef462e4 to your computer and use it in GitHub Desktop.
successor method
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