When I was working for eCommerce Companies, I had a question about how I should design a website that would attract more customers’ attention and make ordering easier, so I became interested in website design and studied HTML and CSS. While I was studying those two codes I was wondering how the site finds and open the pages that I was looking for, so I decided to study more. Thankfully, Amazon provided the way and I was thankfully accepted into the Flatiron School.
During the course, I noticed that the HTML and CSS I learned were simple design coding that colored sketches, whereas I thought JavaScript is complicated because it is the programming that executes it. In the middle of learning a lot of things, I was getting answers little by little to what I was curious about before.
I was curious when I search for the name of an item on Amazon.com, how the site brings up the page I want among other pages. However, now I understand that the system uses filter() or find() to call pages.
filter()
For example, if you look at the code below, you have an array and function.
We know that we can iterate through the array to find the words contains from the search and give a result for the word that contains it, like how example finds out apple and grapes by searching only "ap".
Let's look at another example.
If you search for "Lip", it will look for the name that contains the word "Lip" and the result will give all four items except ColorStay Suede Ink.
find ()
Find is very similar to filter(), however, find() will return the first element that passed the provided function test.
Let's say we have the same array as above.
Function code and the result will be
The result gave the Couture Lipstick Satin instead of Ultra Rouge Lipstick because Couture Lipstick Satin is the first element and before the Ultra Rouge Lipstick.
So whenever we search for a word on amazon.com or Google, that's how the website finds the product or pages to bring it to us.
Thank you for time reading this post, I hope this helped you to understand how the filter() and find() work.





Top comments (0)