Skip to content

Conversation

@SuperSimpleDev
Copy link
Owner

No description provided.


// If a search exists in the URL parameters,
// filter the products that match the search.
if (search) {
Copy link

@antaugustol antaugustol Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it like this:

  if (search) {
    search = search.toLowerCase()
    filteredProducts = products.filter(product => {
      return product.name.toLowerCase().includes(search) ||
        product.keywords.includes(search);
    })
  }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the same thing and it worked. U are smart, that's nice.

Copy link

@maasch maasch Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is mine efficient like his ? :

if(key){
    const searchTerm = key.toLowerCase();

    filteredProducts = products.filter((productData)=>{
      const searchData = (productData.name + productData.keywords.join(' ')).toLowerCase();
      console.log(searchData)
      return searchData.toLowerCase().includes(searchTerm)
    }) 
  }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antaugustol
Your code would be correct if "const search" is changed to "let search"...Otherwise, it will throw an error saying constant variable can't be changed.

@SuperSimpleDev 's code throws it's own sets of errors. In the best case that it works, it is case sensitive meaning if you searched for "cover" it will show results but if you search "Cover", there will be zero matches...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants