我有这个简单的数组,我想从低到高排序:
"80", "84", "115", "98", "128", "131", "132", "128", "139", "140", "141", "142", "142", "124", "144", "145", "148", "149", "152", "97"
为了对其进行排序,我使用sort
,但输出不是我所期望的。
这是我的代码:
def try_order
unordered = ["80", "84", "115", "98", "128", "131",
"132", "128", "139", "140", "141", "142",
"142", "124", "144", "145", "148", "149", "152", "97"]
p "Unordered list is #{unordered}."
ordered = unordered.sort
p "Ordered list is #{ordered}."
end
try_order
输出如下:
"Unordered list is 80841159812813113212813914014114214212414414514814915297."
"Ordered list is 11512412812813113213914014114214214414514814915280849798."
如您所见,有序列表不是从较小的数字(即 80)开始,而是以 1 开头的 3 位数字开头。
有什么我想念的吗?