Last active
April 8, 2018 09:58
-
-
Save isabellachen/53d3a3c1d4dda481d9a0c8cf504f9c3d to your computer and use it in GitHub Desktop.
Given an array of ids to keep, filter an object whoes keys match the ids in the array
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
const travisRepos = { | |
'1995928': {name: "tp-yarra", slug: 'codeworksbcn/tp-yarra'}, | |
'2208412': {name: "tp-paint-fill", slug: 'codeworksbcn/tp-paint-fill'}, | |
} | |
const firebaseRepos = { | |
'1995928': {active: false, name: "tp-yarra", time: 60}, | |
'2208412': {active: false, name: "tp-paint-fill", time: 60}, | |
'1983769': {active: false, name: "tp-two-adds", time: 60}, | |
'2451579': {active: false, name: "tp-diamond", time: 60}, | |
'2451589': {active: false, name: "tp-evented-thing", time: 60}, | |
} | |
const toKeepArr = (destination, source) => { | |
return Object.keys(destination).filter(key => { | |
return Object.keys(source).indexOf(key) !== -1 | |
}) | |
} | |
const filterDestination = (idsToKeep, destination) => { | |
const filteredDestination = {} | |
const arrOfDestinationObjectsWithId = idsToKeep.forEach(id => { | |
filteredDestination[id] = destination[id] | |
}) | |
return filteredDestination | |
} | |
const result = filterDestination(toKeepArr(firebaseRepos, travisRepos), firebaseRepos) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment