[英]Check if all elements in array are the same value
I have an array 'sub_status_arr' which contains a set of values. 我有一个数组“ sub_status_arr”,其中包含一组值。
If all elements in that array are 52, a button is displayed, else something else is displayed. 如果该数组中的所有元素均为52,则显示一个按钮,否则显示其他内容。
I tried the following but it does not seem to work properly. 我尝试了以下操作,但似乎无法正常工作。 It is only checking if the array contains 51 and ignoring the rest
它仅检查数组是否包含51并忽略其余部分
<%if sub_status_arr.include? 51 || 53 || 54 %>
display button
<% else %>
do something else
<% end %>
How do I check if all elements in the array are 52? 如何检查数组中的所有元素是否都是52?
Thanks for your suggestions 谢谢你的建议
I would try the all?
我会尽力
all?
function: 功能:
if sub_status_arr.all? {|ss| ss == 52}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.