8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RubyでArrayから重複した値を取り出す方法

Last updated at Posted at 2019-02-27

今回はRubyでArrayから重複した値を取り出す方法を紹介します。

RubyでArrayから重複した値を取り出す方法

a = [1, 1, 2, 3, 4, 4, 5]
a.select{|v| a.count(v) > 1}.uniq # [1, 4]

selectとuniqを組み合わせるのがポイントです。
以上になります。

終わりに

私は現在、Web3のサービスの開発をしています。詳しくはこちらの記事をご覧下さい。
無料でイーサリアムが当たる、Web3時代の寄付サイトを作った話

8
4
4

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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?