4 ms·
It took me a bit to dig through the fringe cases to find the combination (or maybe an additional combination?) to pull that off. x = '' y = '-Infinity' z = -
by exo128 9y ago
It took me a bit to dig through the fringe cases to find the combination (or maybe an additional combination?) to pull that off.
x = ''
y = '-Infinity'
z = -1
x < y // true: '-Infinity' (y) doesn't get coerced into a number, so '' < 'any string with at least 1 character'
y < z // true: '-Infinity' (y) compares with a number, so it coerces to -Infinity, which is less than -1 (z)
z < x // true: '' (x) is compared with a number, so it coerces to 0, which is greater than -1 (z)
Thank you for the brain exercise!
P.S. - No one ever use crap like this in production code!
- justinpombrio 9y agoOh interesting. The triple I found used the same general idea of values that sometimes coerce to a number, but it made use of octal values instead of Infinity.