Last active
August 29, 2015 14:20
-
-
Save scaint/36ae892dea41defd7f1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
input_array = [1, 2, 1, 4, 1.0, 1r] | |
require 'set' | |
Set.new(input_array).to_a | |
# => [1, 2, 4, 1.0, (1/1)] | |
unique_elements = [] | |
input_array.each { |el| unique_elements << el unless unique_elements.include?(el) } | |
unique_elements | |
# => [1, 2, 4] | |
unique_elements = {} | |
input_array.each { |el| unique_elements[el.hash] = el unless unique_elements.key?(el.hash) } | |
unique_elements.values | |
# => [1, 2, 4, 1.0, (1/1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment