我有以下数组:
passing_grades = ["A","B","C","D"] student2434 = ["F","A","B"]
我需要验证student数组中的所有元素都包含在passing_grades数组中.在上面的场景中,student2434将返回false.但是这个学生:
student777 = ["C","B"]
会回归真实.我尝试过类似的东西:
if student777.include? passing_grades then return true else return false end
没有成功.任何帮助表示赞赏.
解决方法
PASSING_GRADES = ["A","D"] def passed?(grades) (grades - PASSING_GRADES).empty? end
类似于CDub但没有bug.在我看来更具可读性