Skip to content

Instantly share code, notes, and snippets.

@thesabbir
Created April 28, 2016 10:06
Show Gist options
  • Save thesabbir/1d05ad1170ab875d4cb1d33b245cd5d1 to your computer and use it in GitHub Desktop.
Save thesabbir/1d05ad1170ab875d4cb1d33b245cd5d1 to your computer and use it in GitHub Desktop.
function filterFriends(friends, id, status) {
const nextStatus = status === 'available' ? 'unavailable' : 'available';
const online = [];
const offlineFriends = friends.filter((friend) => {
if (friend.contact_uuid !== id && friend.status !== status) {
friend.status = nextStatus;
return true;
}
friend.status = status;
online.push(friend);
return false;
});
return {
online,
offlineFriends,
available: online.length
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment