From bce3d5b372934c5d94ff18d52dc6b7375c2405fb Mon Sep 17 00:00:00 2001 From: Shaun Hamilton <51722130+Sky020@users.noreply.github.com> Date: Fri, 20 Nov 2020 08:21:21 +0000 Subject: [PATCH] fix(learn): remove white space for quick fix (#40231) * fix(learn): remove white space for quick fix Co-authored-by: Nicholas Carrigan (he/him) --- ...lter-or-reduce-to-solve-a-complex-problem.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem.md index ba90a88630..4af8b13ecb 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem.md @@ -1,49 +1,53 @@ --- id: 587d7b88367417b2b2512b45 -title: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem +title: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem challengeType: 1 forumTopicId: 301311 --- ## Description +
Now that you have worked through a few challenges using higher-order functions like map(), filter(), and reduce(), you now get to apply them to solve a more complex challenge.
## Instructions +
We have defined a function named squareList. You need to complete the code for the squareList function using any combination of map(), filter(), and reduce() so that it returns a new array containing only the square of only 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 [-3, 4.8, 5, 3, -3.2]. Note: Your function should not use any kind of for or while loops or the forEach() function.
## Tests +
```yml tests: - text: squareList should be a function. testString: assert.typeOf(squareList, 'function'), 'squareList should be a function'; - - text: for or while loops or forEach should not be used. + - text: for, while, and forEach should not be used. testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g)); - text: map, filter, or reduce 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 array. testString: assert(Array.isArray(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]))); - text: squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]) should return [16, 1764, 36]. testString: assert.deepStrictEqual(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]), [16, 1764, 36]); - text: squareList([-3.7, -5, 3, 10, 12.5, 7, -4.5, -17, 0.3]) should return [9, 100, 49]. - testString: assert.deepStrictEqual(squareList([-3.7, -5, 3, 10, 12.5, 7, -4.5, -17, 0.3]), [9, 100, 49]); + testString: assert.deepStrictEqual(squareList([-3.7, -5, 3, 10, 12.5, 7, -4.5, -17, 0.3]), [9, 100, 49]); ```
## Challenge Seed +
```js -const squareList = (arr) => { +const squareList = arr => { // Only change code below this line return arr; // Only change code above this line @@ -58,10 +62,11 @@ console.log(squaredIntegers);
## Solution +
```js -const squareList = (arr) => { +const squareList = arr => { const positiveIntegers = arr.filter(num => { return num >= 0 && Number.isInteger(num); });