Skip to content

Instantly share code, notes, and snippets.

@vaichidrewar
Created October 27, 2013 01:51
Show Gist options
  • Save vaichidrewar/7177042 to your computer and use it in GitHub Desktop.
Save vaichidrewar/7177042 to your computer and use it in GitHub Desktop.
Array manipulations zip , flatten, compact
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