我想检查排序后的数组值是否递增 1
例如
[1, 2, 3, 4, 5] = TRUE [1, 2, 8, 9, 10] = FALSE
非常感谢任何建议
array = [1,2,4,3] array.sort.each_cons(2).all? { |x,y| y == x + 1 }