Skip to content

Instantly share code, notes, and snippets.

@dmfilipenko
Last active December 28, 2015 14:09
Show Gist options
  • Save dmfilipenko/7512551 to your computer and use it in GitHub Desktop.
Save dmfilipenko/7512551 to your computer and use it in GitHub Desktop.
function getFriends( userId, people ){
var user, friendList, friendsIdList, friendsList = null;
function checkUser( id ){
return people[id]
}
function findPeople( id ){
var foundPerson;
people.forEach( function ( person ){
if ( person.id === id ) foundPerson = person;
} );
return foundPerson;
}
function getFriendsIdList( user ){
friendList = user ? user.friends : null;
return friendList;
}
function getFriendsList( friendsList ){
var _friends = [];
var list = friendsList || [];
_friends = list.map( findPeople );
return _friends;
}
if ( checkUser( userId ) ) {
user = findPeople( userId );
friendsIdList = getFriendsIdList( user );
friendsList = getFriendsList( friendsIdList );
}
return friendsList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment