問題:
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