In javascript Infinity
is always larger than any other number except itself, while -Infinity
is always smaller. What is an analogue of that for characters, i.e. what are the value of a string c
for which c.localCompare(anyString)
would always return (+/-)1 respectively (obviously except when c === anyString
)?
In practice this will be used to sort objects based on 2 flags and the groupName
property, which will be keyed in by users into another piece of software under input validation constraints, so won't be an empty string. (I would need to check to see if someone could 'attack' the script by pasting lots of 0xFFFF into name prompt.)
If something like Infinity
existed, the callback for sort()
would look like this:
(n1, n2) =>
(n1.flag1 ? plusCharInfinity :
n1.flag2 ? minusCharInfinity :
n1.groupName).localeCompare(
n2.flag1 ? plusCharInfinity :
n2.flag2 ? minusCharInfinity :
n2.groupName)
I.e. if flag1 === true
then demote to the bottom; if flag2 === true
- promote to the top; otherwise use the given groupName
value.