【发布时间】:2020-01-05 15:47:18
【问题描述】:
我有 2 个数组:
[2, 4, -2, 4, 1, 3]
["a", "b", "c", "d", "e", "f"]
我希望它们按数字数组排序:
// output
[-2, 1, 2, 3, 4, 4] // <-sorted by numerical order
["c", "e", "a", "f", "b", "d"] // sorted exactly the same order as the first array
虽然“b”或“d”先出现实际上并不重要(在此示例中它们都有 4)
我在网上找到了很多关于此的问题,但没有一个对我有用,谁能帮我解决这个问题?
【问题讨论】:
-
数组可以有不同的长度吗?那么如何处理呢?
标签: javascript arrays sorting