ES6: Write Higher Order Arrow Functions

ES6: Write Higher Order Arrow Functions
0

#1

I am reading but this just is not making sense to me… I am getting the filtered numbers… but the squaring part of the function just does not seem to magically appear through the fog…
Here is my latest code :


const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
  "use strict";
  // change code below this line
let squaredIntegers =realNumberArray.filter(num)=>(num%2===0&&num>0); 
 squaredIntegers=squaredIntegers.map((num)=>num*num);

  // change code above this line
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

#teachmelikeImFive LOL…

Thank you in advance for your kind consideration…


#2

Hello, @BrBearOFS. You’ve almost made it. Just a few changes:

  1. Check quotes symbols (line 3) and change them to proper once ’ … ’ or ‘’ … "
  2. Your filter statement should be put in () like so:
    .filter((num)=>(num%2===0&&num>0))
  3. While using map make sure that you assign your logic to each array element:
    .map((num)=>num = num* num)

If you make these slight changes your code will work and you’ll see magic happening :slightly_smiling_face:


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

Two of these are bad advice

The type of quotation marks do not matter

Using (num) => num = num * num is pointless, though it happens to give you the right answer also, (num) => num * num is idiomatic


#5

I see what you’re trying to do with your filter function, but you’ll find it easier to filter usingNumber.isInteger

Once filter has its argument sorted you’re basically done, nice work


#6

You can map the filter itself

let squaredIntegers = realNumberArray.filter(num)=>(num%2===0&&num>0).map((x)x*x);

#7

Villian,

THank you for the point in the direction… once I added the additional parenthesis, it passed and I was busy kicking myself for not seeing it… …

I appreciate the time and response.

Mark


#8

Neveon,

Thank you for your response… I do have a question…

in the .map((x)xx) ; portion… is there no operator of some sort necessary ?
like the .map ((x)+>x
x) ?

Thank you again…


#9

Thank you Ariel …

I will endeavor not to be THAT guy LOL…


#10

THank you Gebulmer,

I did see the IsInteger () on I think it was stackflow… there was some reason it was bumped down because of something to do with its methodology or interpolation… I will have to go back and look again…
however, yes ! it would clear some of the typing… :slight_smile:

Thank you for your time and response…


#11

My b man, you’re right. I overlooked my code. Its a transformation of the filter so yeah.

let squaredIntegers = realNumberArray.filter((num)=>num%2===0&&num>0).map((x)=>x*x);