Skip to content

Instantly share code, notes, and snippets.

@automaticalldramatic
Last active April 29, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save automaticalldramatic/e1e1e773662faafdecfbbb8e05452c83 to your computer and use it in GitHub Desktop.
Save automaticalldramatic/e1e1e773662faafdecfbbb8e05452c83 to your computer and use it in GitHub Desktop.
// this method accepts the property to order by. In our example, this would be priority
// sortByDesc('priority')
sortByDesc(prop: string) {
return this.returnedCardsArr.sort((a, b) => a[prop] < b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
}
// also a slightly verbose way of keeping only unique IDs replacing the ones received from the new call - cause the data also might have changed.
for (const card of c) {
if (!this.uniqueMap.has(card.id)) {
this.uniqueMap.set(card.id, true);
this.returnedCardsArr.push(card);
continue;
}
this.returnedCardsArr = this.returnedCardsArr.filter((foundCard) => foundCard.id !== card.id);
this.returnedCardsArr.push(card);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment