简体   繁体   English

元素数量可变的数组的排序数组

[英]Sorting Array of Arrays having variable number of elements

I have to sort an array of arrays. 我必须对数组进行排序。 I've searched for solutions however my problem is: 我一直在寻找解决方案,但是我的问题是:

  1. need to sort arrays that may have different sizes from a script run to another. 需要对从脚本运行到另一个的大小可能不同的数组进行排序。
  2. need to sort not only by one or two elements, but, if possible based in all elements. 不仅需要按一个或两个元素进行排序,而且还需要根据所有元素进行排序。

For example, for the following inputs: 例如,对于以下输入:

[[2,3,4,5,6],[1,3,4,5,7],[1,3,4,5,8]]
[[5,2,3],[2,2,4],[2,2,5]]

The output should be, respectively: 输出应分别为:

[[1,3,4,5,7],[1,3,4,5,8],[2,3,4,5,6]]
[[2,2,4],[2,2,5],[5,2,3]]

Do as below 做如下

input=[[2,3,4,5,6],[1,3,4,5,7],[1,3,4,5,8]] 
input.sort # => [[1, 3, 4, 5, 7], [1, 3, 4, 5, 8], [2, 3, 4, 5, 6]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM