freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../es6/use-destructuring-assignmen...

1.9 KiB

id title challengeType forumTopicId dashedName
587d7b8a367417b2b2512b4d Usare l'assegnazione destrutturante per passare un oggetto come parametro a una funzione 1 301217 use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters

--description--

In alcuni casi, è possibile destrutturare l'oggetto in un argomento funzione.

Considera il codice qui sotto:

const profileUpdate = (profileData) => {
  const { name, age, nationality, location } = profileData;

}

Questo destruttura efficacemente l'oggetto passato alla funzione. Questo può anche essere fatto sul posto:

const profileUpdate = ({ name, age, nationality, location }) => {

}

Quando profileData viene passato alla funzione qui sopra, i valori del parametro vengono destrutturati per l'utilizzo all'interno della funzione.

--instructions--

Usa l'assegnazione destrutturante all'interno dell'argomento della funzione half per inviare solo max e min all'interno della funzione.

--hints--

stats dovrebbe essere un object.

assert(typeof stats === 'object');

half(stats) dovrebbe essere 28.015

assert(half(stats) === 28.015);

Dovresti ricorrere alla destrutturazione.

assert(__helpers.removeWhiteSpace(code).match(/half=\({\w+,\w+}\)/));

Dovresti utilizzare il parametro destrutturato.

assert(!code.match(/stats\.max|stats\.min/));

--seed--

--seed-contents--

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};

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

--solutions--

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};

const half = ( {max, min} ) => (max + min) / 2.0;