-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWherefore_art_thou.js
More file actions
23 lines (23 loc) · 1.1 KB
/
Wherefore_art_thou.js
File metadata and controls
23 lines (23 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function whatIsInAName(collection, source) {
var sK = Object.keys(source);
return collection.filter(x => sK.every(y => x[y] === source[y]));
}
/*
function whatIsInAName(collection, source) {
var sourceKey = Object.keys(source);
return collection.filter(function (x) {
return sourceKey.every(function (y) {
return x[y] === source[y];
});
}
);
}
*/
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
// should return [{ first: "Tybalt", last: "Capulet" }].
whatIsInAName([{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }], { "a": 1 });
// should return [{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }].
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
// should return [{ "a": 1, "b": 2 }, { "a": 1, "b": 2, "c": 2 }].
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
// should return [{ "a": 1, "b": 2, "c": 2 }].