Sort strings by using “less/greater than” comparison operators in comparator

后端 未结 2 1717
长发绾君心
长发绾君心 2020-12-21 00:00

Today I found a strange for me implementation of strings sorting:

[\'Data\', \'Chata\', \'Clata\'].sort(function(a, b) { return a > b});

2条回答
  •  無奈伤痛
    2020-12-21 00:51

    When comparing strings, comparison is done letter by letter. So c has lower symbol value than d (Check this table)

提交回复
热议问题