Passing FtoJ as a subgroup instead would've logged only F with a value of 100000.
Only once the for condition is fixed to check for i <= group instead.
Also const group = (values & subgroup) >>> 0; is needed — otherwise bit 31 won't be recognized.
taking the opportunity to introduce >>> too, which is the unsigned right shift operator.
Given the context I think n >>> 0 needs an introduction as well, i.e. in general bitwise operators yield Int32 — however >>> yields a Uint32 (hence the name; Alternate implementations of ToUint32 and ToInt32).
Please note that 31 is the maximum possible bit value here, while the previous version would've reached up to 53 without issues.
Given that the previous version uses group & i it's just as bound to the 32 bit limit. That said the limit can be widened to 53 bits without resorting to BigInt.
Awesome review, thank you! I have addressed pretty much all your points but I won't go down the 1 << 31 and beyond rabbit hole, although you are right the post was misleading, and I actually had to (2 ** 31) & 1 to indeed realize that all operations are broken regardless the fact the integer is theoretically safe, as Number.MAX_SAFE_NUMBER would suggest. I guess I would've learned it the hard way once added more values to some code I'm working on, so apologies for that misleading bit, now removed, and thanks again for the hints 👍
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Only once the
forcondition is fixed to check fori <= groupinstead.Also
const group = (values & subgroup) >>> 0;is needed — otherwise bit 31 won't be recognized.Given the context I think
n >>> 0needs an introduction as well, i.e. in general bitwise operators yieldInt32— however>>>yields aUint32(hence the name; Alternate implementations of ToUint32 and ToInt32).Given that the previous version uses
group & iit's just as bound to the 32 bit limit. That said the limit can be widened to 53 bits without resorting toBigInt.Awesome review, thank you! I have addressed pretty much all your points but I won't go down the
1 << 31and beyond rabbit hole, although you are right the post was misleading, and I actually had to(2 ** 31) & 1to indeed realize that all operations are broken regardless the fact the integer is theoretically safe, asNumber.MAX_SAFE_NUMBERwould suggest. I guess I would've learned it the hard way once added more values to some code I'm working on, so apologies for that misleading bit, now removed, and thanks again for the hints 👍