Created
October 27, 2013 01:51
-
-
Save vaichidrewar/7177042 to your computer and use it in GitHub Desktop.
Array manipulations zip , flatten, compact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zip | |
• zip interleaves the element of its receiver with those of its argument, using nil to pad if the first array is longer than the second; that is, [:a,:b,:c].zip([1,2])==[[:a,1],[:b,2],[:c,nil]] | |
flatten | |
• flatten takes an array that includes arbitrarily nested arrays and flattens them into a single array with no nested arrays, that is, [[:a,1],[:b,2],[:c,nil]].flatten==[:a,1,:b,2,:c,nil] | |
compact | |
• compact removes nil elements from a collection, that is, [:a,1,:c,nil].compact==[:a,1,:c] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment