Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何根据另一个向量的值对一个向量进行排序?
假设我有预定义的顺序:
(def order ["0M","6M","1Y","2Y","3Y"])
我有另一个向量["0M","1Y","6M"](可能包含也可能不包含向量“订单”的所有元素)
["0M","1Y","6M"]
输出应该是["0M","6M","1Y"]
["0M","6M","1Y"]
(def order ["0M","6M","1Y","2Y","3Y"]) (sort-by #(.indexOf order %) ["0M", "1Y", "6M"]) ; ("0M" "6M" "1Y")
请注意,它sort-by返回一个序列。如果您绝对需要矢量结果,可以将输出提供给vec.
sort-by
vec