Write Higher Order Arrow Functions NEED HELP with FILTER,REDUCE function, explain what to be done with these

Tell us what’s happening:

Your code so far


const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  
  const squaredIntegers = arr;
  // change code above this line
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions

Hi there.
At this task you have to use arrow functions which have next look : (argument) => { do some here } .

Use map or reduce or filter function to go throught the array and do math with arguments.

You have to math the square of each positive digit in the array.
Lets try to write kinda pseudo-code.
How you do it in real life? You take an array ( [1, -3, 10] for instance) and look at first argument. Is it positive? yes. Then you return 1 * 1. Next step: second argument of the array = -3. Is it positive? No, skip it. And move on to the last index of the array.

Don’t forget that in JavaScript you can assign any instance to a varible. For example:
let digit = 3;
let string = ‘hi there’;
let firstFunction = function() {}; // do the same as secondFunction
let secondFunction = () => {}; // do the same as firstFunction

You always can read this article to understand this question deeper: MDN: Arrow Functions.

Here is some links which will help you to solve this task:
Array.prototype.map()
Array.prototype.reduce()
Array.prototype.filter()

Here is links to some solutions. But it would be better if you’ll try to solve it yourself.

Solution 1

Solution Link

Solution 2

Issue on the github

Stay tune.

1 Like