I'm stuck with this question Destructuring should be used

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
const half = (function() {
"use strict";  // Only change code below this line
return function half(stats) {
// use function argument destructuring
const{min,max} = stats;
  return (max + min) / 2.0;
// Only change code above this line

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters

Link to the challenge:

Hi @cyemz09, the aim of the challenge is to teach you that you can use destructuring directly in the function arguments itself.
It’s a very neat feature that you will extensively use and probably find many other people using as well.

As example.
Let’s image we are working with some user object that is coming from the database.
The user informations contains a lot of data.
We have a function that greets the user, so it needs only two fields.

const user1 = {
  name: "Clark",
 surname: "Kent",
 profession: "Journalist",
 age: "unknown",

const greet = (user) => `Hello ${user.name} ${user.surname}. Welcome Back`

greet(user1) // 'Hello Clark Kent. Welcome Back'

And it works just fine.
But we can refactor that function so that it destructure the object directly in the argument.

const greet = ({name, surname}) => `Hello ${name} ${surname}. Welcome Back`

greet(data) // 'Hello Clark Kent. Welcome Back'

We got the exact same output as before.

In your case you are not destructuring in the function argument, but in the function body.
Also why the use of a IIFE?
The challenge already have a function as starter.

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