如何檢查一個值是否存在於 Ruby 中的數組中 - How to check if a value exists in an array in Ruby

問題:

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?有沒有一種簡單的方法來檢查值是否存在,僅此而已?


解決方案:

參考一: https://stackoom.com/question/8KkU
參考二: How to check if a value exists in an array in Ruby
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章