Make ArbitraryBase Unicode-aware#1299
Conversation
appgurueu
left a comment
There was a problem hiding this comment.
The fix is sensible if Unicode is to be supported but it worsens the time complexity since .at is linear time in the size of the base string rather than constant time. Consider extracting the Unicode characters into an array as "preprocessing".
I'm not convinced that's true — surely accessing an array index is constant time, just like accessing an object property. There's no reason for The only linear time parts I added were these: const baseOneCharacters = [...baseOneCharacterString]
const baseTwoCharacters = [...baseTwoCharacterString]But they only run once per function call, and in any case, the first argument is already iterated prior to being reversed. |
There was a problem hiding this comment.
Nevermind, you're correct. Glancing over the changes I missed the spread operators and confused Array.at with String.at, of which I had incorrectly assumed that it was linear time (it is not, it's constant time - it's basically just charAt + negative index support).
Is there any particular reason to prefer x.at(y) over x[y] here though? y will always be positive, so I'd prefer standard array indexing here.
Additionally, it would be good if you could convert the "test comments" into proper Jest tests.
Thanks for the fix.
|
@appgurueu Should I wait for the changes you suggested or good to merge? |
|
Changing 'abc'.charAt(1.5) // b
;[...'abc'].at(1.5) // bHowever, as a result, the loop was being iterated over many more times than necessary as I've fixed that by using floor division and removing the regex replacement. |
https://mathiasbynens.be/notes/javascript-unicode#counting-symbols
Describe your change:
Checklist:
Example:
UserProfile.jsis allowed butuserprofile.js,Userprofile.js,user-Profile.js,userProfile.jsare notFixes: #{$ISSUE_NO}.