Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找一种将一维数组除以数字 n 的方法,以创建一个多维数组,每个元素(最多)长度为 n。例如
[1,2,3,4,5,6] / 3
应该导致:
[[1,2,3],[4,5,6]]
这个应该做...
chunkedArr = arr.each_slice(3).to_a;