ruby如何判断一个数组和一个字符串之间是否有相同Q元素

Python017

ruby如何判断一个数组和一个字符串之间是否有相同Q元素,第1张

c中是strstr.

ruby 1.9.3中包含:

include? other_str → true or false click to toggle source

Returns true if str contains the given string or character.

"hello".include? "lo" #=>true

"hello".include? "ol" #=>false

"hello".include? ?h #=>true

数组

array = [[1],[2],[3],[0],[1,2],[1,0],[0,1]]

希望排序整个数组,先按照数组 元素个数 ,如果个数相同再 按照首个元素大小

array.sort_by {|a| [a.size, a[0]] }