Skip to content

Instantly share code, notes, and snippets.

@mlomnicki
Last active December 19, 2015 09:39
Show Gist options
  • Save mlomnicki/5934363 to your computer and use it in GitHub Desktop.
Save mlomnicki/5934363 to your computer and use it in GitHub Desktop.
Check if two arrays have exactly the same elements (we don't care about order)
# Check if two arrays have exactly the same elements (we don't care about order)
keys = [2,1]
1. keys.sort == [1, 2]
2. Set.new(keys) == [1,2].to_set
3. (keys - [1,2]).empty?
4. (keys - [1,2,]).size == 0
5. Your idea?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment