Array Methods Flashcards
1
Q
what does Array#each_slice do?
A
it splices the array into slices of length n
2
Q
how would you split an array into slices of a fixed length?
A
Array#each_slice
3
Q
what does Array#each_cons do?
A
it will run a window of length n over an array, returning each slice that the window covers.
[0,1,2,3,4].each_cons(2) will return [[0,1],[1,2],[2,3],[3,4]]
4
Q
how do you find all left-to-right says of numbers in an array, given length n?
A
Array#each_cons