map()
, filter()
, and reduce()
, you now get to apply them to solve a more complex challenge.
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.
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]);
```