Algorithm of JavaScript “sort()” Function

前端 未结 8 765
灰色年华
灰色年华 2020-12-02 17:48

Recently when I was working with JavaScript \"sort()\" function, I found in one of the tutorials that this function does not sort the numbers properly. Instead to sort numbe

8条回答
  •  攒了一身酷
    2020-12-02 18:30

    The “default” comparison function calls toString on both values and does a lexicographical comparison on the string representations. V8 engine uses Timsort algorithms which runs in O(nlogn). Source

提交回复
热议问题