LoginSignup
2
1

More than 5 years have passed since last update.

.uniqの逆がしたい!

Last updated at Posted at 2014-10-02

配列の中で重複しているものだけ抜き出す方法

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

はできる。

[1,2,3,4]だけ抽出したいときは

arr.select{|a| arr.index(a)!=arr.rindex(a)}.uniq

でできる

2
1
1

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
2
1