forked from sgrouples/javascript-assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex06.js
70 lines (55 loc) · 1.28 KB
/
ex06.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Return a function that takes a list of valid users, and returns a function that returns true if all of the supplied users exist in the original list of users.
You only need to check that the ids match.
## Example
var goodUsers = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
]
// `checkUsersValid` is the function you'll define
var testAllValid = checkUsersValid(goodUsers)
testAllValid([
{ id: 2 },
{ id: 1 }
])
// => true
testAllValid([
{ id: 2 },
{ id: 4 },
{ id: 1 }
])
// => false
## Arguments
* goodUsers: a list of valid users
Tip: you can use array#some and Array#every or _.includes
*/
function checkUsersValid(validUsers) {
return function(usersToTest) {
return usersToTest.every(function(testUser) {
return validUsers.some(function(validUser) {
return validUser.id === testUser.id;
});
});
}
}
var goodUsers = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
]
// `checkUsersValid` is the function you'll define
var testAllValid = checkUsersValid(goodUsers)
var testOne = testAllValid([
{ id: 2 },
{ id: 1 }
])
// => true
var testTwo = testAllValid([
{ id: 2 },
{ id: 4 },
{ id: 1 }
])
// => false
console.log('test one:', testOne);
console.log('test two:', testTwo);