Last active
August 29, 2015 14:02
-
-
Save morenoh149/13ff590cca3d1ef1c540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem 05 every some | |
/* | |
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 | |
Use array#some and Array#every to check every user passed to your returned | |
function exists in the array passed to the exported function. | |
## Resources | |
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/every | |
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some | |
## Boilerplate | |
function checkUsersValid(goodUsers) { | |
return function(submittedUsers) { | |
// SOLUTION GOES HERE | |
}; | |
} | |
module.exports = checkUsersValid | |
*/ | |
function isInGoodUsers(submittedUser, index, array){ | |
return goodUsers.some(function(goodUser, index, array){ | |
return goodUser.id === submittedUser.id; | |
}); | |
} | |
function checkUsersValid(goodUsers){ | |
return function(submittedUsers){ | |
submittedUsers.every(isInGoodUsers); | |
}; | |
} | |
module.exports = checkUsersValid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment