Skip to content

Instantly share code, notes, and snippets.

@weird-coon
Created June 26, 2020 03:06
Show Gist options
  • Save weird-coon/9b7186917001161f577bacb0880ca641 to your computer and use it in GitHub Desktop.
Save weird-coon/9b7186917001161f577bacb0880ca641 to your computer and use it in GitHub Desktop.
Get single Element
getSpSingleItems(petState: TextValue[]): string[] {
const filterState: TextValue[] = [...petState].reverse()
let i: number = filterState.length
while (i--) {
if (i - 1 >= 0) { // remove element if 2 continue is normal item
if (!filterState[i].longText && !filterState[i - 1].longText) {
filterState.splice(i, 1)
filterState.splice(i - 1, 1)
i = i - 1
}
}
}
return filterState.filter((item: any) => !item!.longText) // remove long item
.map((item: any) => item.name) // single element item name
}
isSingleItem(name: string): boolean {
return this.spSingleItems.includes(name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment