sorting unique values in an array with Ruby -
is there way write method
in ruby takes array of items , returns array without duplicates. without using ruby’s uniq
method?
so, output of array [1,5,"frog", 2,1,3,"frog"]
[1,5,"frog",2,3]
you getting unexpected end-of-input because using parenthesis instead of braces denote block. try:
my_array.to_a.select{ |i| != }
but isn't quite you'd expect. here alternative:
my_array.group_by{|item| item}.keys
hope helps
Comments
Post a Comment