Created
November 4, 2019 21:54
-
-
Save jasonknight/06c5dd4d615386a9185c805baf06e29a 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
var users = [ | |
{ | |
role: 'admin', | |
email: 'fakeadmin1@email.com' | |
}, | |
{ | |
role: 'user', | |
email: 'fake2@email.com' | |
}, | |
{ | |
role: 'admin', | |
email: 'fakeadmin2@email.com' | |
}, | |
]; | |
function getUsers(master_user_list, wherefunc) { | |
var user_list = []; | |
for ( var i = 0; i < master_user_list.length; i++ ) { | |
if ( wherefunc(master_user_list[i]) ) | |
user_list.push(master_user_list[i]); | |
} | |
return user_list; | |
} | |
var admin_emails = getUsers(users,function (u) { | |
return u.role == 'admin'; | |
}).map(function (u) { | |
return u.email; | |
}); | |
console.log(admin_emails); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment