Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created September 19, 2016 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/26771e58c3a4961ba1e2a7830b97351c to your computer and use it in GitHub Desktop.
Save mooreniemi/26771e58c3a4961ba1e2a7830b97351c to your computer and use it in GitHub Desktop.
# pair the sublists together
a.zip(b)
=> [[[1], [9]], [[2, 3], [8, 7]], [[4, 5, 6], [6, 5, 4]]]
# collect up the lengths
a.zip(b).collect {|e| e.map(&:length) }
=> [[1, 1], [2, 2], [3, 3]]
# i want each pair of lengths to be the same, so
a.zip(b).collect {|e| e.map(&:length) }.map(&:uniq)
=> [[1], [2], [3]]
# after i made them uniq, are they singular?
a.zip(b).collect {|e| e.map(&:length) }.map(&:uniq).all? {|e| e.size == 1 }
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment