Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby array with unique values

require 'set'

array = ['foo', :bar, 'foo', :foobar]
# Sets are much faster than arrays
# when it comes to checking for inclusion,
# intersections etc
set = array.to_set #=> #<Set: {"foo", :bar, :foobar}>
array = set.to_a
p array #=> ["foo", :bar, :foobar]
 
PREVIOUS NEXT
Tagged: #ruby #array #unique #values
ADD COMMENT
Topic
Name
9+1 =