LoginSignup
1
1

More than 5 years have passed since last update.

array.ununiq

Last updated at Posted at 2016-06-28
uniq.rb
array = %w(1 1 2 3 4 5 5 6 7 8 9 9 9).map(&:to_i)
=> [1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 9]

array.uniq
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]

重複はuniqメソッドで簡単に取り除ける。
じゃあ重複した値を確認したい時は?

ununiq.rb
array.select { |a| array.index(a) != array.rindex(a) }.uniq
=> [1, 5, 9]

既出の恐れが高い

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1