ES6 - Use Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
I see that this question has been complained about over a year and a half ago, and yet instead of just fixing the problem, the respondents in the older thread just deny that a problem exists.

I am by no means an expert, but I scored a 61 for JavaScript on my most recent Pluralsight JS test, have already used destructuring in thousands of lines of code; and this question absolutely floored me.

It is entirely unclear that the stats object is being passed into the function. Furthermore, at the point someone is learning this material, if they have only done the Javascript Basics tutorial…IT HAS NEVER YET BEEN EXPLAINED THAT YOU CAN ASSIGN A VARIABLE AS A FUNCTION!!

So in one fell swoop you’re introducing a function that has to be called by the variable with a parameter, and you’re NOT EVEN SHOWING THE CALL.

Just fix the damn question and stop wasting people’s time.

I still don’t think that there is a problem with the question. I there there is a problem where somehow people get to this point in the curriculum and don’t understand that a function definition can be correct even though you don’t see the function call.

You maybe missed the lesson on arrow functions where functions are show as being assigned to a variable.

In any case, the entire JS curriculum is being rewritten, so I don’t see anyone rewriting this single lesson in the interim.

I didn’t miss it. I didn’t do JavaScript Algorithms and Data Structures yet because it is literally the last course in the list.

Still not really the point though, even if you have a grasp on arrow functions the question should just show you that stats is being passed into the function call. Because even after one guesses their way to the correct answer, it still looks like voodoo because they’re just learning destructuring and this question makes it look like destructuring is doing something magical with the stats const. I really don’t see why this is so hard to grasp.

It is part of the ES6 course, right before the lesson you are talking about, so yes, you seem to have missed it.

I still think the core of the issue is that learners are stuck is this bizzare pikaboo state. That is a big problem that shouldn’t be masked with a band-aid. This comes up in a few places where a handful of learners utterly fail to understand function arguments if they don’t see the function called and I don’t know where to fix such a fundamental flaw in understanding.

Hmmmm…not sure that I agree with you. If I don’t see the function called, then I don’t know if you’re going to call it behind the scenes or if I’m supposed to call it. That’s number one. If you’re calling it, I don’t know if you’re passing in the parameter or not. Maybe I’m supposed to pass stats in as the default variable, and destructure the default. You’re assertion is that ‘I should just know they’re calling the function and passing stats in’. If that’s the case, why don’t you show the function call? How is that not understanding arguments?

In retrospect, what I should have done is removed the parameters entirely and replaced them with a rest variable and logged it at the beginning of the function. Why didn’t I do that? I’m really not sure…I do recall being quite confused from the outset of reading the example. I do recall that the first thing I tried was

// Only change code below this line
const half = ({max, min} = stats) => (max + min) / 2.0; 
// Only change code above this line

Which results in…

// running tests
// Destructuring should be used.
// tests completed

Obviously I found this quite confusing since…it IS using destructuring? It was all downhill from there.

Another note: The title of the assignment is “Use Destructuring Assignment to Pass an Object as a Function’s Parameters.” Is that an accurate description of the task? Because to me even that title is confusing and misleading.

Yes. That is an accurate description of the challenge. A destructuring assignment is used inside of the functions argument list.

You know if you are required to call the function or not because the instructions explicitly tell you what you need to accomplish. Deciding to do extra things that aren’t part of the instructions and change the functional behavior of the code is usually wrong. That’s how instructions and requirements typically work.

I’m not sure how someone would think the tests work if you read

half(stats) should be 28.015

And don’t assume that the function is called.

But that’s not what I am talking about. The whole idea of needing to see a function call for every single function is a problem. Somehow a small handful of users are completely missing the fact that calling a function with arguments is how data gets passed in and the function argument values set and that process is independent of the function definition. That is a critical flaw in understanding. I think explicitly shadowing the global variable with the function arguments might be making that worse.

I think someone could argue that too much boilerplate code and such might be distracting. The point is that the instructions simply say to change the function. They don’t tell you to call the function, they don’t tell you if or how it will be called.

By this point I think it’s safe to assume that learners understand that tests are being run behind the scenes. We’re what? 100 challenges in at this point? Sure, we could take the time to talk about how unit tests and test runners work. I think that might be distracting.

If you take a flying lesson, and you are learning how to taxi, and you stop because you don’t understand how the engine works, an appropriate response from the teacher is, “That’s OK, that’s a good question, but let’s not worry about that right now. Let’s assume that that was all taken care of by someone that knows what they were doing. We can’t stop what we’re doing and spend 3 months answering that question. You don’t need to worry about it for now, but you can learn about it later if you want.”

It’s hard coming up with a learning path. This is a common issue - what to temporarily skip over and/or over-simplify to keep from getting bogged down in details. Sometimes there is no perfect solution that everyone will agree is “best”. (Something that you think would clarify something might distract or confuse someone else.) To be honest, I don’t agree 100% with every decision FCC has made. But I think on average, they’re doing a very good job. A lot of people have learned to code and a lot have gotten jobs. I’m one of them. #ymmv

Things can be improved. If you feel like you have an improvement, discuss it in the Contributors forum or go create a ticket on the repo and try it there.

My suggestion would be to realise that this is not perfect, but is pretty damn good, and just roll with it and keep learning. If you have a question, reach out - that’s why we’re here. I like that you’re invested in making things better, but I might suggest to remember that on a team this big, there is a lot of compromise, and I might also suggest to get a little more experience coding and dealing with the difficulties of teaching coding to a global audience at different levels and educations and online in small, bite size chunks… before making quick judgements. I don’t mean that as a jab - just focus on learning.

1 Like

I see what you’re saying on one hand. Would be nice if there were any type of reciprocal empathic thinking on your side. You point out where my thinking is in a “bizzare pikaboo state” but don’t seem capable of responding to any of the valid issues I’m bringing up.

I’m content to make this my last response.

Just because I don’t think you are correct and I’m not agreeing with you doesn’t mean I’m not responding to what you are saying. It just means I’m not giving you the response you want.

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