Skip to content

Instantly share code, notes, and snippets.

@tanmancan
Created October 22, 2019 21:51
Show Gist options
  • Save tanmancan/7c85c17c50390ecb0974586746e7428e to your computer and use it in GitHub Desktop.
Save tanmancan/7c85c17c50390ecb0974586746e7428e to your computer and use it in GitHub Desktop.
Free search using .match()
unmappedListings() {
return this.listings
.filter(listing => !listing.node.abbListingID)
.filter((listing) => {
if (this.search) {
const searchTerm = this.search.trim()
.toLowerCase()
.split(' ')
.join('|');
const regex = new RegExp(`(${searchTerm})`, 'g');
const isListing = listing.node.name.toLowerCase()
.match(regex);
const isPmsId = listing.node['Unit Code'].toLowerCase()
.match(regex);
return (isListing && isListing.length > 0)
|| (isPmsId && isPmsId.length > 0);
}
return true;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment