kokojambo,
наличие в элементе свойств a и b
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<ul class="list"></ul>
<script>
function fn(arr, pattern) {
return arr.filter(function(el) {
return pattern.some(function(mask) {
return Object.keys(mask).every(function(key) {
return mask[key](el[key])
})
})
})
};
var arr = [{a : 10, id : "a", b : 17}, {b : 12, id : "b"}, {c : 15, id : "c"}],
pattern = [{a :function(a) {
return a !== undefined
},
b : function(b) {
return b !== undefined
}}
],
arrFilter = fn(arr, pattern),
html = arrFilter.reduce(function(html, el) {
return html += '<li class="item" ><div>'+JSON.stringify(el, null, 4)+'</div></li>'
},"");
document.querySelector(".list").innerHTML = html;
</script>
</body>
</html>