Last active
December 28, 2015 14:09
-
-
Save dmfilipenko/7512551 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
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