所有的东西都是真的!
完善编辑器中的every函数,如果集合(collection)中的所有对象都存在对应的属性(pre),并且属性(pre)对应的值为真。函数返回ture。反之,返回false。
代码:
function every(collection, pre) {
// Is everyone being true?
var bCheck=true;
for(var i in collection){
if(!collection[i][pre]){
bCheck=false;
}
}
return bCheck;
}
every([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
热门评论
var result=collection.every(function(obj){ return obj[pre];
}); return result;