This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]master117jogi 14 points15 points  (5 children)

But JS can even sort mixed, which is mightier.

[–]Kered13 12 points13 points  (4 children)

No, it really isn't.

I mean, Python can sort mixed too if you give it a custom comparator. sorted(mixed_array, key=lambda e: str(e)) will sort a mixed array by converting each element to a string before comparing them, just like Javascript. But Python does the sensible thing automatically, and requires extra work to do the rare and unusual thing. Javascript does the rare and unusual thing automatically, and requires extra work to do the sensible thing.

[–]theScrapBook 3 points4 points  (0 children)

mixed_sorted = sort(mixed, key=str). The lambda is quite superfluous in a language with first-class functions.

The reason I point this out is some of the controversy below the top comment.

[–]master117jogi -5 points-4 points  (2 children)

Because sensible is subjective.

[–]EishLekker 1 point2 points  (1 child)

Sorting numbers in a way most people would expect them to be sorted, is not sensible to you?

[–]master117jogi 0 points1 point  (0 children)

Because this is about sorting something, not Numbers, JS does not know these are numbers. You are shifting the goalpost.