divide an array by the size
2014-07-13 19:00
330 查看
For example,i have an array :[2,4,6,7,9,12,1],i want to divide it by the size [2,2,3]
the output that i want is:
The way looks correct, you can do it more succinctly using
of
Or, using
the output that i want is:
[[2,4],[6,7],[9,12,1]]
The way looks correct, you can do it more succinctly using
mapinstead
of
each:
c = b.map{|m| a.shift(m)}
Or, using
&methodshorthand:
c = b.map(&a.method(:shift)) # => [[2, 4], [6, 7], [9, 12, 1]]
相关文章推荐
- Given an array of size n, find all the possible sub set of the array of size k
- How to combine the value of multiple hashes within an array by the same key
- How do I sort an array of hashes by a value in the hash?
- How do I sort an array of hashes by a value in the hash?
- Whats the best way to split an array in ruby into multiple smaller arrays of random size
- Given an array of size n, find the majority element. The majority element is the element that appear
- You get an error when you attempts to save SSIS packages to the MSDB package store if the network packet size >=16388 By
- 面试题: generate an equation, by inserting operator add ("+") and minus ("-") among the array to make equationExpression == 0
- GeeksforGeeks Sort an array according to the order defined by another array
- An established connection was aborted by the software in your host machine
- How to Capture the Integer-Divide-By-Zero Error in C++(提前定义信号)
- Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method
- Incorrect decrement of the reference count of an object that is not owned at this point by the caller1
- It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing ___Error Installing APK
- Eclipse上JPA报错:Target Entity is not a entity 和the "mapped by" attribute has an invalid mapping type
- Data Structure Array: Find the two numbers with odd occurrences in an unsorted array
- Each child in an array or iterator should have a unique "key" prop. Check the render method of `Tabl
- The JSP specification requires that an attribute name is preceded by whitespace
- Algorithm: Make all the odd numbers precede all the even numbers in an array.
- This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_