| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | --- | 
					
						
							|  |  |  | id: 587d7b88367417b2b2512b44 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | title: Escribe funciones flecha con parámetros | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | challengeType: 1 | 
					
						
							|  |  |  | forumTopicId: 301223 | 
					
						
							|  |  |  | dashedName: write-arrow-functions-with-parameters | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # --description--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | Al igual que una función regular, puedes pasar argumentos a una función flecha. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const doubler = (item) => item * 2; | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | doubler(4); | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | `doubler(4)` devolvería el valor `8`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Si una función flecha tiene un solo parámetro, los paréntesis que encierran el parámetro pueden ser omitidos. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const doubler = item => item * 2; | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | Es posible pasar más de un argumento a una función flecha. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const multiplier = (item, multi) => item * multi; | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | multiplier(4, 2); | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | `multiplier(4, 2)` devolverá el valor `8`. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | # --instructions--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | Reescribe la función `myConcat` que añade el contenido de `arr2` a `arr1` para que la función use la sintaxis de función flecha. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # --hints--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | Debes reemplazar la palabra clave `var`. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | (getUserInput) => assert(!getUserInput('index').match(/var/g)); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | `myConcat` debe ser una variable constante (utilizando `const`). | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | (getUserInput) => assert(getUserInput('index').match(/const\s+myConcat/g)); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | `myConcat` debe ser una función de flecha con dos parámetros | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert( | 
					
						
							|  |  |  |   /myConcat=\(\w+,\w+\)=>/.test(code.replace(/\s/g, '')) && | 
					
						
							|  |  |  |     typeof myConcat === 'function' | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | `myConcat()` debe devolver `[1, 2, 3, 4, 5]`. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert.deepEqual(myConcat([1, 2], [3, 4, 5]), [1, 2, 3, 4, 5]); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 00:31:24 -06:00
										 |  |  | La palabra clave `function` no debe ser usada. | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | (getUserInput) => assert(!getUserInput('index').match(/function/g)); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # --seed--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## --seed-contents--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | var myConcat = function(arr1, arr2) { | 
					
						
							|  |  |  |   return arr1.concat(arr2); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log(myConcat([1, 2], [3, 4, 5])); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # --solutions--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const myConcat = (arr1, arr2) =>  { | 
					
						
							|  |  |  |   return arr1.concat(arr2); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log(myConcat([1, 2], [3, 4, 5])); | 
					
						
							|  |  |  | ``` |