Files
.github
api-server
client
config
curriculum
__fixtures__
challenges
_meta
arabic
chinese
english
portuguese
russian
spanish
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
compare-scopes-of-the-var-and-let-keywords.spanish.md
create-an-export-fallback-with-export-default.spanish.md
create-strings-using-template-literals.spanish.md
declare-a-read-only-variable-with-the-const-keyword.spanish.md
explore-differences-between-the-var-and-let-keywords.spanish.md
import-a-default-export.spanish.md
mutate-an-array-declared-with-const.spanish.md
prevent-object-mutation.spanish.md
set-default-parameters-for-your-functions.spanish.md
understand-the-differences-between-import-and-require.spanish.md
use--to-import-everything-from-a-file.spanish.md
use-arrow-functions-to-write-concise-anonymous-functions.spanish.md
use-class-syntax-to-define-a-constructor-function.spanish.md
use-destructuring-assignment-to-assign-variables-from-arrays.spanish.md
use-destructuring-assignment-to-assign-variables-from-nested-objects.spanish.md
use-destructuring-assignment-to-assign-variables-from-objects.spanish.md
use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.spanish.md
use-destructuring-assignment-with-the-rest-operator-to-reassign-array-elements.spanish.md
use-export-to-reuse-a-code-block.spanish.md
use-getters-and-setters-to-control-access-to-an-object.spanish.md
use-the-rest-operator-with-function-parameters.spanish.md
use-the-spread-operator-to-evaluate-arrays-in-place.spanish.md
write-arrow-functions-with-parameters.spanish.md
write-concise-declarative-functions-with-es6.spanish.md
write-concise-object-literal-declarations-using-simple-fields.spanish.md
write-higher-order-arrow-functions.spanish.md
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
comment-dictionary.js
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.acceptance.test.js
getChallenges.js
getChallenges.test.js
gulpfile.js
lib.js
package-entry.js
package-lock.json
package.json
utils.js
cypress
docs
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.npmrc
.prettierignore
.prettierrc
.snyk
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
HoF.md
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
crowdin.yml
cypress-install.js
cypress.json
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
jest.config.js
lerna.json
lighthouserc.js
package-lock.json
package.json
sample.env
freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.spanish.md

74 lines
2.5 KiB
Markdown
Raw Normal View History

2018-10-08 13:34:43 -04:00
---
id: 587d7b8a367417b2b2512b4d
title: Use Destructuring Assignment to Pass an Object as a Function's Parameters
challengeType: 1
2018-10-10 16:20:40 -04:00
videoUrl: ''
localeTitle: Utilice la asignación de destrucción para pasar un objeto como parámetros de una función
2018-10-08 13:34:43 -04:00
---
## Description
<section id="description"> En algunos casos, puede destruir el objeto en un argumento de función. Considere el siguiente código: <blockquote> const profileUpdate = (profileData) =&gt; { <br> const {nombre, edad, nacionalidad, ubicación} = profileData; <br> // haz algo con estas variables <br> } </blockquote> Esto destruye efectivamente el objeto enviado a la función. Esto también se puede hacer en el lugar: <blockquote> const profileUpdate = ({nombre, edad, nacionalidad, ubicación}) =&gt; { <br> / * hacer algo con estos campos * / <br> } </blockquote> Esto elimina algunas líneas adicionales y hace que nuestro código se vea limpio. Esto tiene la ventaja adicional de no tener que manipular un objeto completo en una función — solo los campos que son necesarios se copian dentro de la función. </section>
2018-10-08 13:34:43 -04:00
## Instructions
2018-10-10 16:20:40 -04:00
<section id="instructions"> Use la asignación de desestructuración dentro del argumento de la función <code>half</code> para enviar solo <code>max</code> y <code>min</code> dentro de la función. </section>
2018-10-08 13:34:43 -04:00
## Tests
<section id='tests'>
```yml
tests:
- text: <code>stats</code> deben ser un <code>object</code> .
testString: 'assert(typeof stats === "object", "<code>stats</code> should be an <code>object</code>.");'
- text: <code>half(stats)</code> debe ser <code>28.015</code>
testString: 'assert(half(stats) === 28.015, "<code>half(stats)</code> should be <code>28.015</code>");'
- text: Se utilizó la destrucción.
testString: 'getUserInput => assert(getUserInput("index").match(/\(\s*\{\s*\w+\s*,\s*\w+\s*\}\s*\)/g), "Destructuring was used.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
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"; // do not change this line
// change code below this line
return function half(stats) {
// use function argument destructuring
return (stats.max + stats.min) / 2.0;
};
// change code above this line
})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
2018-10-10 16:20:40 -04:00
2018-10-08 13:34:43 -04:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>