question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 - Write Higher Order Arrow Functions - About Chaining, Needs Clarification

See original GitHub issue

Describe your problem and - if possible - how to reproduce it

Challenge ES6 - Write Higher Order Arrow Functions The examples show moving from normal function to the ES6 arrow function. However, the challenge is about “chaining” multiple functions together. It is super unclear how the example code would lead one to chaining a filter and map function together. This is really a better discussion for the functional programming section.

Additionally, the filter function requires that users understand how to determine if a number is an integer or not. There is nothing in the prior curriculum which would make it clear to a new coder how to do this. While you do talk about the “parseInt” function, it’s never used in the context of comparing a number to itself. A better filter function might be “positive numbers” instead, which is a much simpler comparison.

I was attempting to help someone understand this one today and I was initially flummoxed as to how to solve it.

Once I realized it was about chaining, I was able to write a solution like this:

const squaredIntegers = arr
    .filter(elem => elem == parseInt(elem))
    .map(elem => elem * elem);

I don’t believe that there is another way to solve this using higher order functions and arrow functions. There is no solution in the seed file, so I’m not sure exactly what the authors had in mind.

In short, this challenge badly needs clarification and simplification. It may be entirely inappropriate for this section of challenges. I could see it after a new challenge called “How to Chain Higher Order functions” or something like that.

Add a Link to the page with the problem

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:16
  • Comments:31 (17 by maintainers)

github_iconTop GitHub Comments

14reactions
SaintPetercommented, Jun 7, 2018

I just reviewed the curriculum leading up to this challenge.

  1. There doesn’t appear to be an introduction to the concept of a callback function or functions as first class object.
  2. No introduction to anonymous functions (except two challenges prior)
  3. No mention of either map or filter

All told, I think this challenge should just be removed or moved to the functional programming section.

8reactions
moT01commented, Jun 7, 2018

I would agree with this issue - I got real stuck on it knowing quite well how to use the array methods - it doesn’t say anything about using .map and it is not used or taught at all up to this point - same with testing if it’s an integer - that’s not too tough to figure out I don’t think, but it does complicate things - the challenge description only talks about using .filter and the instructions say…

Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers.

From those instructions it seems like the challenge wants you to use just .filter to accomplish this - challenges are supposed to teach a single thing, this one introduces too much and feels way too complicated - and it isn’t clear to me what we are even supposed to be learning on this one

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Another solutions?] ES6: Write Higher Order Arrow Functions
Yes. Many array methods return an array so can be chained. I would still filter first, then map as it seem clearer to...
Read more >
ES6 Arrow Functions and Promise Chaining condensed ...
When you call .then() , it expects you to pass it a function reference and when that function is called, it will be...
Read more >
Archived | Higher order functions in ES6:Easy as a => b => c
We're going to look at one such case here: how arrow functions make it easier to write higher-order functions in ES6.
Read more >
5 Best Practices to Write Quality Arrow Functions
Best practices on how to write quality, readable and concise arrow functions in JavaScript.
Read more >
How To Use Javascript Arrow Functions & This Keyword
ES6 introduced a new way of writing JavaScript functions called arrow ... To call an arrow function and reuse it, you need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found