Last active
December 9, 2021 10:19
-
-
Save alx8437/278721f0e4c4962c472a9dcad02cbb95 to your computer and use it in GitHub Desktop.
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 actualSymbolsFromStore: Symbol[] = yield select(SymbolSelectors.byServerIdPresetId(serverId, presetId)); | |
const oldSymbolsFromModelTypes: Symbol[] = modelTypes[0].symbols; | |
// Change order | |
const takeActualSymbols: Symbol[] = actualSymbolsFromStore.filter((actualSymbol) => | |
oldSymbolsFromModelTypes.find((oldSymbol) => actualSymbol.id === oldSymbol.id), | |
); | |
or | |
// Don't change order | |
const takeActualSymbols: Symbol[] = []; | |
oldSymbolsFromModelTypes.forEach((oldSymbol) => { | |
actualSymbolsFromStore.forEach((storeSymbol) => { | |
if (oldSymbol.id === storeSymbol.id) { | |
takeActualSymbols.push(storeSymbol); | |
} | |
}); | |
}); | |
or lodash | |
const ids = [1, 2] | |
const objects = [{ id: 1, foo: 'bar' }, { id: 2, foo: 'baz' }, { id: 3, foo: 'quux' }] | |
const result = _.intersectionWith(objects, ids, (o, id) => o.id === id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment