Write Higher Order Arrow Functions - function keyword not used?

Write Higher Order Arrow Functions - function keyword not used?
0

#1

Tell us what’s happening:

I had gotten every other requirement right, except the “function keyword was not used.” one. Not getting it. I had even
used it in my code. What am I doing wrongly?

Your code so far


const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  //const squaredIntegers = realNumberArray.filter(function(number){
  //  if(number % 1 == 0 && number >0){
  //    return number*number;
  //  }
  //});

  const squaredIntegers_pre = realNumberArray.filter(number => number % 1 == 0 && number >0);
  
  const squaredIntegers = squaredIntegers_pre.map(function(num1){
    return num1 * num1;
  });

  // 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; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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


#2

The exercise is expecting you to use ES6 syntax. Therefore passing in

function(num1){
    return num1 * num1;
  }

as a callback in your map won’t work. Use the syntax like you used on filter. :sunglasses:


#3

In addition to what @shimphillip mentions, there is a slight bug in the test which is picking up your commented code which also has the word function in it. Get rid of that commented code also or it will not pass either.


#4

@shimphillip @RandellDawson This worked! Thanks! :smiley:


#5

I was flagged… why?


#6

It would have been so much more clear for me if the requirement was: function keyword must not be used. I thought I was wrong for not having used the function keyword…
And warming up to ES6 syntax in this early stage of the course is rough when combined with brushing up on higher order functions, method chaining and using Math… or not, using isInteger or not…