Last active
November 17, 2019 08:08
-
-
Save taingmeng/df0dc4d596c7cb0f38596beccbdfee38 to your computer and use it in GitHub Desktop.
Example of refactoring duplicated code
This file contains hidden or 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
// Before | |
const isUserTagged = (user, photo) => { | |
return photo.taggedUsers.map(user => user.id).includes(user.id) | |
} | |
const isUserBlocked = (user, photo) => { | |
return photo.user.blockedFriends.map(user => user.id).includes(user.id) | |
} | |
// After | |
const isUserIn = (user, userPool) => { | |
return userPool.map(user => user.id).includes(user.id); | |
} | |
const isUserTagged = (user, photo) => { | |
return isUserIn(user, photo.taggedUsers); | |
} | |
const isUserTagged = (user, photo) => { | |
return isUserIn(user, photo.blockedFriends); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment