fix(learn): remove white space for quick fix (#40231)
* fix(learn): remove white space for quick fix Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
This commit is contained in:
		| @@ -6,27 +6,30 @@ forumTopicId: 301311 | |||||||
| --- | --- | ||||||
|  |  | ||||||
| ## Description | ## Description | ||||||
|  |  | ||||||
| <section id='description'> | <section id='description'> | ||||||
| Now that you have worked through a few challenges using higher-order functions like <code>map()</code>, <code>filter()</code>, and <code>reduce()</code>, you now get to apply them to solve a more complex challenge. | Now that you have worked through a few challenges using higher-order functions like <code>map()</code>, <code>filter()</code>, and <code>reduce()</code>, you now get to apply them to solve a more complex challenge. | ||||||
| </section> | </section> | ||||||
|  |  | ||||||
| ## Instructions | ## Instructions | ||||||
|  |  | ||||||
| <section id='instructions'> | <section id='instructions'> | ||||||
| We have defined a function named <code>squareList</code>.  You need to complete the code for the <code>squareList</code> function using any combination of <code>map()</code>, <code>filter()</code>, and <code>reduce()</code> so that it returns a new array containing only the square of <em>only</em> the positive integers (decimal numbers are not integers) when an array of real numbers is passed to it.  An example of an array containing only real numbers is <code>[-3, 4.8, 5, 3, -3.2]</code>. | We have defined a function named <code>squareList</code>.  You need to complete the code for the <code>squareList</code> function using any combination of <code>map()</code>, <code>filter()</code>, and <code>reduce()</code> so that it returns a new array containing only the square of <em>only</em> the positive integers (decimal numbers are not integers) when an array of real numbers is passed to it.  An example of an array containing only real numbers is <code>[-3, 4.8, 5, 3, -3.2]</code>. | ||||||
| <strong>Note:</strong> Your function should not use any kind of <code>for</code> or <code>while</code> loops or the <code>forEach()</code> function. | <strong>Note:</strong> Your function should not use any kind of <code>for</code> or <code>while</code> loops or the <code>forEach()</code> function. | ||||||
| </section> | </section> | ||||||
|  |  | ||||||
| ## Tests | ## Tests | ||||||
|  |  | ||||||
| <section id='tests'> | <section id='tests'> | ||||||
|  |  | ||||||
| ```yml | ```yml | ||||||
| tests: | tests: | ||||||
|   - text: <code>squareList</code> should be a <code>function</code>. |   - text: <code>squareList</code> should be a <code>function</code>. | ||||||
|     testString: assert.typeOf(squareList, 'function'), '<code>squareList</code> should be a <code>function</code>'; |     testString: assert.typeOf(squareList, 'function'), '<code>squareList</code> should be a <code>function</code>'; | ||||||
|   - text: for or while loops or forEach should not be used. |   - text: <code>for</code>, <code>while</code>, and <code>forEach</code> should not be used. | ||||||
|     testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g)); |     testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g)); | ||||||
|   - text: <code>map</code>, <code>filter</code>, or <code>reduce</code> should be used. |   - text: <code>map</code>, <code>filter</code>, or <code>reduce</code> should be used. | ||||||
|     testString: assert(__helpers.removeJSComments(code).match(/\.(map|filter|reduce)\s*\(/g)); |     testString: assert(__helpers.removeWhiteSpace(__helpers.removeJSComments(code)).match(/\.(map|filter|reduce)\(/g)); | ||||||
|   - text: The function should return an <code>array</code>. |   - text: The function should return an <code>array</code>. | ||||||
|     testString: assert(Array.isArray(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]))); |     testString: assert(Array.isArray(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]))); | ||||||
|   - text: <code>squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2])</code> should return <code>[16, 1764, 36]</code>. |   - text: <code>squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2])</code> should return <code>[16, 1764, 36]</code>. | ||||||
| @@ -38,12 +41,13 @@ tests: | |||||||
| </section> | </section> | ||||||
|  |  | ||||||
| ## Challenge Seed | ## Challenge Seed | ||||||
|  |  | ||||||
| <section id='challengeSeed'> | <section id='challengeSeed'> | ||||||
|  |  | ||||||
| <div id='js-seed'> | <div id='js-seed'> | ||||||
|  |  | ||||||
| ```js | ```js | ||||||
| const squareList = (arr) => { | const squareList = arr => { | ||||||
|   // Only change code below this line |   // Only change code below this line | ||||||
|   return arr; |   return arr; | ||||||
|   // Only change code above this line |   // Only change code above this line | ||||||
| @@ -58,10 +62,11 @@ console.log(squaredIntegers); | |||||||
| </section> | </section> | ||||||
|  |  | ||||||
| ## Solution | ## Solution | ||||||
|  |  | ||||||
| <section id='solution'> | <section id='solution'> | ||||||
|  |  | ||||||
| ```js | ```js | ||||||
| const squareList = (arr) => { | const squareList = arr => { | ||||||
|   const positiveIntegers = arr.filter(num => { |   const positiveIntegers = arr.filter(num => { | ||||||
|     return num >= 0 && Number.isInteger(num); |     return num >= 0 && Number.isInteger(num); | ||||||
|   }); |   }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user