Advertisement
Hubermann

Ruby - Appears a odd number of times

Oct 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.19 KB | None | 0 0
  1. def odd_frequency(array)
  2. hash_counter = Hash.new(0)
  3. final = []
  4. array.each do |v|
  5. hash_counter[v] += 1
  6. end
  7. hash_counter.each { |k,v| final << k if v % 2 != 0 }
  8. print final
  9. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement