Javascript Coding Challenges for Beginners Q13

Transcript

English (Auto-generated)

one. Welcome back to my Javascript coding challenge for beginners. Today will be working on questions 13 and today we want to return the full name of all the people who uses Apple phones. So here we're giving a person array, we have the first name, last name and the phone of choice that they use. So using what we've learned in the previous exercises, we can solve this challenge by using those built in array functions. So when you're ready, pause the video and come up with their own solution and when you're ready you can press play again and we'll solve the problem together. So now that you're ready, let's tackle the solution. So the first thing we do is because we have an array object that were given inside are a bunch of objects. The most likely method that we're gonna use is filter because we want to filter out the kind of phone that they use. So the first thing we're gonna do is we're gonna let result. We call our dot filter. Remember that filter takes in a parameter, We can call it element or anything you want of your choice. And we're simply going to return element dot phone because we want to access the phone of each element and we want to make sure that the phone is equal to Apple because that's what we're searching for. So it's equal to Apple. Now because our filter is going to filter out all of the people that use this Apple phone, we're most likely gonna get john doe and tim cook. However, were not done because we still want to return the phone name of the people who uses the Apple phone. So next you can either set it to a new variable or you can change it to map. So if you guys don't remember what map does map returns, you can manipulate all of the name's inside each of these objects. So in this case we'll call it person or you can call it element you want. But I'm just saying person because these are the people's names that we want and now we simply want to return a person not me. That's christian thought last night. And now don't forget we want to return the results because our answer is stored inside this result variable. So now let's run the terminal and see if we get the answer that we want to run load 13 nauseous. And as you can see we got john doe and chemicals the only two people who uses Apple phone, some of you may be like why can't we just filtered out with our dot filter. So if you guys remember that filter only filters out everything that returns. True. But you cannot manipulate the object. So if you want to manipulate the object you would have to change it with map in order to get the first and last name. So thank you all for watching. And when you're ready we can go onto the next challenge. Mm hmm
104 Views 0 Likes 0 Comments

Find all the people who uses Iphones!

Comment
Leave a comment (supports markdown format)