JS Built-ins
StringString.prototype.localeComparebeginner

String.prototype.localeCompare() β€” greater-than returns positive

πŸ“– Usage Example
'apple'.localeCompare('banana')   // β†’ negative
'banana'.localeCompare('apple')   // β†’ positive
'abc'.localeCompare('abc')        // β†’ 0

Use localeCompare() to compare strings in a locale-aware way, returning negative, zero, or positive.

String.prototype.localeCompare() β€” Greater Than

When str sorts after compareString, the result is positive.

Challenge: Implement comesAfter(a, b) that returns true when a sorts after b.

comesAfter('b', 'a') // β†’ true
comesAfter('a', 'b') // β†’ false
πŸ’‘ Hints (1)
  • β€’ A positive return value means the first string sorts after the second.