且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查数组元素的大小相同的

更新时间:2023-11-18 23:30:58

怎么样使用的 可枚举所有#? 方法?

What about using the Enumerable#all? method?

def element_of_same_size?(arr)
  arr.all? { |a| a.size == arr.first.size }
end

element_of_same_size?([[1,2], [3,4], [5]])
# => false

element_of_same_size?([[1,2], [3,4], [5, 6]])
# => true