0
具有以下陣列紅寶石:數組排序,不包括第一排
[["Date", "Value"], ["2014-09-25", 0], ["2014-09-23", 1], ["2014-09-22", 0], ["2014-09-24", 2]]
我怎樣才能排除從排序後的第一行數組數組排序?
具有以下陣列紅寶石:數組排序,不包括第一排
[["Date", "Value"], ["2014-09-25", 0], ["2014-09-23", 1], ["2014-09-22", 0], ["2014-09-24", 2]]
我怎樣才能排除從排序後的第一行數組數組排序?
使用本:
[arr[0]].concat(arr[1..arr.length].sort)
其中ARR是你的陣列
演示:
2.1.1 :001 > arr = [["Date", "Value"], ["2014-09-25", 0], ["2014-09-23", 1], ["2014-09-22", 0], ["2014-09-24", 2]]
=> [["Date", "Value"], ["2014-09-25", 0], ["2014-09-23", 1], ["2014-09-22", 0], ["2014-09-24", 2]]
2.1.1 :002 > [arr[0]].concat(arr[1..arr.length].sort)
=> [["Date", "Value"], ["2014-09-22", 0], ["2014-09-23", 1], ["2014-09-24", 2], ["2014-09-25", 0]]
你可以這樣做:
ary = [["Date", "Value"], ["2014-09-25", 0], ["2014-09-23", 1], ["2014-09-22", 0], ["2014-09-24", 2]]
header = ary.shift
ary.sort.unshift header
#=> [["Date", "Value"], ["2014-09-22", 0], ["2014-09-23", 1], ["2014-09-24", 2], ["2014-09-25", 0], ["Date", "Value"]]
排除'[ 「日期」,「值「]'?對 ? – aelor 2014-09-25 10:58:38
是的,不包括'[「Date」,「Value」]' – Triple 2014-09-25 10:59:40