配列の中に値が入っているか確認[和訳]
hey, guys :)
さて、今日も和訳すっか!
今回は質問者に859、回答者に1331のいいね!がついている人気の記事である。
そんなにいい質疑応答だったのか!?って気になるよね。
ーー質問ーー
I have a value ‘Dog’ and an array [‘Cat’, ‘Dog’, ‘Bird’].
訳)'Dog'という値と[‘Cat’, ‘Dog’, ‘Bird’]の配列がある。
How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more?
どうやったらループしないで値が配列に入っているか確認できるんだ?シンプルに確認できないか?
ーー回答ーー
You’re looking for include?:
>> ['Cat', 'Dog', 'Bird'].include? 'Dog' => true
訳)君が探しているのはinclude?だ。
>> ['Cat', 'Dog', 'Bird'].include? 'Dog' => true
–終わり–
え?これだけ?w
いいね!が多い記事は難しい話に突っ込むようなイメージがあったが、シンプルなのが意外に明白で評判いいのかもしれない。
この記事を読んだ時最初は拍子抜けだったが、あっさりすぎて次第にエンジニア初心者の私に勇気を与えてくれているような気がした。
ありがとう、user211662(質問者)とBrian Campbell(回答者)。君たちのあっさりさは人に勇気を与えた。
Thank you user211662 and Brian Campbell. Your simplenesses are giving me a hope and courage.
Hope you two will check my blog someday. God bless you.
end
原文
Check if a value exists in an array in Ruby - Stack Overflow