Files
freeCodeCamp/curriculum/challenges/japanese/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.md
2022-01-20 20:30:18 +01:00

2.0 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8a367417b2b2512b4d 分割代入を使用してオブジェクトを関数のパラメーターとして渡す 1 301217 use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters

--description--

場合によっては関数の引数自体にオブジェクトを分割することもできます。

次のコードを考えてみましょう。

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

}

このように、オブジェクトを分割して関数に渡す効果を得ることができます。 中に記述することもできます。

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

}

profileData が上記の関数に渡されると、関数のパラメーターから値が分割されて、関数内で使用されます。

--instructions--

half 関数の引数内で分割代入を使用して、関数内で maxmin だけを渡してください。

--hints--

statsobject である必要があります。

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

half(stats)28.015 である必要があります。

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

分割を使用する必要があります。

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

分割されたパラメーターを使用する必要があります。

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;