Please expand the explanation for: Use the map Method to Extract Data from an Array

Nope. The callback function can only use the three arguments provided by map.

The first argument passed to the callback function for a map will always be the current array item (and map calls the callback function for every array item).

Solution 2 is using the current array element, destructuring it to extract its title and imdb rating, and then returning a new object formed out of just those two entries.

1 Like

I have to admit: I absolutely hate this about some of the lessons here. There were many instances, where the explanation said something like: “With this methodology we can make X happen”. And I am thinking through this, and think I recognize how it will work and why. But then the task would be something like: “Just do this one little thing to make X happen” and I would be like… :thinking: “Just doing this one little thing won’t actually make X happen, what am I missing?” And then I would look for help and sure enough: You need to do several things to make X happen! So I go back, try to make X happen (as per the instruction) just to realize in the next lesson, that… yes… Now the explanation goes on to the next step and tells me, how the one little step actually didn’t make X happen yet. :face_with_symbols_over_mouth: :man_facepalming:

So my plea would be: Either explain the whole thing from the beginning or make clear, that certain things are just a step in a longer proccess. Or magic in a black box, that I don’t need to understand. But then at least tell me, how to use what comes out of the box.

Ok, it just clicked. Thank you.

Well isn’t that some hidden magic… An argument I never saw or named or passed myself gets passed but then before even becoming humanly recognizable gets transformed (destructured) already to be used later.

So many layers of abstraction. :sweat_smile:

Again, if I’m taking driving lessons, “push on the accelerator and the car speeds up” is sufficient. I don’t need to know about the linkage to the fuel injectors, how the spark plugs work, how the drive train works, how the laws of physics keep the car moving forward, etc. Do I need to learn chemistry? Quantum mechanics? How gasoline is made? How petroleum deposits were formed? Etc.? That is all interesting stuff, but if my goal is to learn the basics of driving, they are a dangerous distraction.

I get it - you have an inquisitive mind and want to learn how things work and why. I am the same way. But I also learned that sometimes I need to suppress that, even if just for the time being.

So my plea would be: Either explain the whole thing from the beginning or make clear, that certain things are just a step in a longer proccess. Or magic in a black box, that I don’t need to understand. But then at least tell me, how to use what comes out of the box.

For the first one, again, if they explained everything to every depth that anyone might want, this curriculum would become humongous, unmanageable, and no one would want to do it.

With you second suggestion, I think we would have to put that caveat in 3-10 places in each lesson - there are a lot of things that get brushed over with “ignore the man behind the curtain”, more than you are realizing. And I think for most people this is implied. If my driving instructor tells me “move this stick like this and the car goes into reverse”, if he doesn’t explain how transmissions work, that’s because I don’t need to know that, at least not at this point. It doesn’t mean that it’s a bad question, but I can infer from the fact that he didn’t bring it up, that it is a moot point for what we are trying to do, assuming he’s a competent teacher.

And again, get used to doing research online - it’s a very important dev skill.

I have been doing research, don’t worry. I found out about the automatic argument passing on my own after all.

But I feel your comparison with the driving instructor is not quite accurate in this instance. I feel like I have been tought (in a manual car): To get into a gear and drive, you have to ease off the gas, push down on the clutch, shift gears with the knob, release the clutch and then press the gas again.

Now this lesson comes along and the driving instructor says: Let’s drive backwards now. To drive backwards there is only one gear and you have to turn around and look out of the rear window. Now do that and drive backwards to that cone over there.

So I think… Ok… There must be a backwards gear that I have to shift into. So I try my whole spiel with the pedals and everything, but it doesn’t work. And I wonder why, because I have done everything, as I have learned it. And then I ask the instructor for more help and he says:
“Don’t worry about that pedal business. As I have just told you, you have to look out of the back window. The car will then automatically chose the aforementioned backwards gear and you just press the gas pedal.”

And yeah… I could have just blindly listened to the instructor and could have ignored most of the things, I learned before. But why would I? And why didn’t the teacher just add “the car will shift gears automatically this time around” in his initial instruction?

This is why I don’t like the ‘its magic’ explanation, personally. (It works for some people but doesn’t work in my head)

There is zero magic (again, in my head).

Up to this point, you have been writing functions that take arguments.

Now you are being shown that you can pass functions into other functions.

You are not being asked to blindly ignore things you have been told before.

Everything you already know is consistent with this new idea.

Functions can be used as arguments to other functions.

map is a function that takes another function as an argument.

Specifically, map makes a new array out of your old array by using your callback function on every item in your old array.

Nothing about that violates anything you’ve been shown before.

Now, how JavaScript internally decides to do this depends upon the specific version of JavaScript inside of your web browser (the specific engine in your car if you will).

To be honest, the internal details can be pretty confusing, which is why we don’t start with them.

I don’t want to debate pedagogy analogies. I spent 30 years as a private music instructor so I have my own ideas of teaching theory.

I’m sorry that this doesn’t work for you. If you think FCC is doing it wrong, then perhaps once you get the skills you can build your own site.

I could have just blindly listened to the instructor and could have ignored most of the things, I learned before. But why would I?

Why would you? Because you are paying someone to teach you.

And why didn’t the teacher just add “the car will shift gears automatically this time around”

To me, I fail to see the difference between “flip this lever like this to put the car in reverse” and “flip this lever like this to put the car in reverse because the car will shift gears automatically”. If you do, then you’re seeing something I’m not.

Based on our conversation, I suspect that you are going to be having this issue a lot. It might be easier to just accept that the rest of the world doesn’t know how to teach like you know is best and learn to deal with it. It is easier to put on a pair of slippers than to carpet the world. And this is 2021 - this is easy to get information. I think it has the potential to lead you down a dangerously unproductive rabbit hole, but if that’s what you want…

But I don’t think I can add anything more useful to this thread so, I’ll bow out. Good luck.

1 Like

My point wasn’t that it involves literal magic. But it can be a handy shorthand for “there is a reason why and how this works the way it does but I don’t want to get bogged down in the details so I’m just going to focus on what it does and not worry about its inner workings”. In my mind, it’s a more colorful way of calling it a black box.

Yeah, I get that. Well, my brain gets that. My gut rebels at the analogy.

1 Like

I really appreciate you trying to help me here, but there seems to be a fundamental misunderstanding about what my problem is (or rather was).

I have no problem understanding and accepting, that functions can take other functions as arguments. That seems well explained in the lesson. My problem is, that never befor has a function just passed arguments without me telling it to. And never befor have I received arguments that I haven’t set myself. And I feel these new circumstances and how to handle and work with them are not (or not well) explained in the lesson.

Just to be sure: I understand how it works. I understood even before I started this thread (apart from solution 2, which you cleared up a few posts ago). I was just trying to communicate, what I perceive as a considerable oversight.

Ah, the peakaboo principle strikes again?

The entire test suite on the left side of your screen has been calling functions for you with arguments you did not pick. You click the ‘run tests’ button and the function you wrote gets called with different arguments.

Same thing here. You call map, and internally map runs the function you provided with different arguments.

You don’t have to watch the line of code be run for it to be valid and have successfully reached an outcome.

I am sorry, if I offended you. That was not my intention.

And I do not think, that I know better than everybody else. I appreciate all your guys and gals work here very much. But I don’t think it is unreasonable for a student to point out, when a book or a teacher could transfer certain parts of knowledge in a more understandable way. Is it?

I am under no illusion to think, that my one thread here is representative of everyone using this platform and that you / FCC will make big changes now.

I also know that such a long conversation would never happen in real life. And I would just shut my mouth after making sure, my point was heard. But since this is an open platform and no one is forced to interact with me, I assume that a conversation is welcome, as long as someone answers.

So once again: Thanks to you all here! Did not mean to imply that the whole of FCC is somehow faulty.

I know that. But these functions were also handwritten and the arguments chosen and passed in by a human. I just did not know that something like map can just “create” arguments on its own. And then I didn’t understand how to use them , because I thought I had to then “talk the language” of the map() to actually get to use these arguments.

map also had its arguments chosen and passed in by a human. Some human wrote the JavaScript engine that is inside of your web browser. Inside of that engine, there is some sort of a loop that roughly looks like

for (let idx = 0; idx < array.length; idx++) {
  newArr.push(callback(array[idx], idx, array));
}

This loop is part of the definition of the map function that every array can call. (As part of the prototype of an Array, as mentioned above)

But once again, with these a human was always the one telling these methods how to do their job by passing in arguments. I did not ask map() to do anything other than iterate through the values of an array. For comparison: In a for-loop iteration through the same array the loop doesn’t automatically give me arguments or any kind of output unless I manually change something or return something. That was my reference frame.

I understand everything you guys are saying. And yes, once you understand it, it is really simple and makes sense. But I still think, that the explanation is not there in the lesson.

Just these two additions would clear up so much. But I have spent enough time here now. Gotta keep on learnin’.

Thank you all!

I agree with you wholeheartedly. The following is very difficult to digest.

When the callback is used, it is passed three arguments. The first argument is the current element being processed. The second is the index of that element and the third is the array upon which the map method was called.

Is this passage really necessary for the beginners to understand how to use map? The passage is confusing because beginners would think somehow you have to pass three arguments to the callback function. It reads like that to me. The passage does not make clear that it is talking about how the map would be implemented. Even if it makes clear, I don’t think it is necessary to be stated here. No beginners would want to know how the map is implemented. They are interested mainly to understand how to use it. If you insist on mentioning it, then do so after explaining how the map works.

This is the only sample map given in this lesson.

const names = users.map(user => user.name);

We need more. Instead of all those “big” statements at the top. Start with an example, and provide additional examples to reinforce learning. Human do not learn from abstract statements, but from concrete examples.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.