exclude any listings on a real estate website that contains the words "price by negotiation" or "auction" in javascript

You can use JavaScript's Array filter() method along with Regular Expressions to exclude listings that contain the words "price by negotiation" or "auction". Here's an example:

index.tsx
const listings = [
  "Apartment for sale",
  "House for sale - Price by negotiation",
  "Land for sale",
  "Office space for lease",
  "Auction: Commercial property"
];

const excludedWords = /(price\s*by\s*negotiation|auction)/i;
const filteredListings = listings.filter(listing => !excludedWords.test(listing));

console.log(filteredListings);
346 chars
13 lines

Output:

index.tsx
["Apartment for sale", "Land for sale", "Office space for lease"]
66 chars
2 lines

In the example above, we create an array called listings that contains the various listings on the real estate website. We define a Regular Expression excludedWords that matches the words "price by negotiation" or "auction" in a case-insensitive manner.

Using the filter() method, we iterate over each listing and keep only the ones that do not match the excludedWords Regular Expression. The resulting filtered array is stored in filteredListings.

Finally, we log the filteredListings array to the console, which contains only the listings that do not contain the excluded words.

Note: This solution assumes that the "listings" variable is an array of strings representing the properties on the real estate website. Modify it according to your specific use case if needed.

gistlibby LogSnag