I feel like fCC suddenly threw me into the deep end with this one and I have literally no clue what to do. ES6 In general seems to have halted my otherwise good pace of progress to a complete stop, I even took a week break because of the ES6 section.
My first confusion comes immediately when I notice the code I’m supposed to change is already within an arrow function
const squareList = (arr) => {
"use strict";
// change code below this line
const squaredIntegers = arr;
// change code above this line
return squaredIntegers;
};
Am I supposed to create a new arrow function that uses the higher order functions? So I’m looking at functions inside of functions inside of functions? This is an odd wall of complexity given the slow ramp up of the previous lessons. I’m not sure what my first step here is.
I wouldn’t even know how to do this without ES6, never mind with it. So it’s odd that the lesson says “It’s time we see how powerful arrow functions are when processing data” considering I have nothing to contrast it with.
I couldn’t figure this challenge out either. However, I noticed that they only had a single test case. I simply told the computer to return the right answer for that specific test case.
You are correct. The partial solution provided already is an arrow function.
It is not obvious but they also require you to use map, filter or reduce in your solution - all of which need a callback function. Any use of the keyword “function” will fail to pass the challenge so any callbacks would need to be arrow functions as well.
I think they were hoping to demonstrate how much cleaner anonymous callbacks could be using arrow functions vs function statements.
Arrow functions take some getting used to but are not all that difficult with practice.
// this
function squareList(arr){
//vs this
const squareList = (arr) => {
If your function is a one-liner, you can do away with brackets and return keyword.
If you only have one parameter you can skip the parenthesis around parameter list.
My advice is to skip this section for now. I personally feel that it’s in the wrong spot in the curriculum, and I’ve made a post about it.
I would do it after you finish the Basic Algorithm Scripting at least. Those challenges are great because they’re going to make you use what you’ve learned in a much more open area. You’ll probably have to look some things up, but they will really solidify what you’ve been studying.
After that, I think ES6 will make a little more sense.
I will be honest here, my advice is to skip the whole ES6 section and instead, learn it from other resources. As you move forward in that section, you will not understand a lot of stuff and will struggle with it like getters and setters. So my advice is to learn ES6 from another place, I’m not saying that freecodecamp is bad, it’s actually so good but I don’t know what happened when they wrote that section, it’s like a different website like W3schools.
Don’t skip topics,
when they are useful, but difficult.
I think the instruction notes are very clear: 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.
If you think about the instructions,
you probably will come to something like: (1) filter my current list for only positive integers => find out how to do this (2) compute the square of every of these positive integers => find out how to do this
The example with the FBPosts on the left side of the lesson is easy to understand.
Bear in mind this comes immediately after the complete beginner section. I understand what to do, and I think the examples are easy to understand, but then I’m past a level where they look like gibberish: that task is trivial if you already know the concepts. It isn’t if you don’t, because you can’t really infer what it’s asking for. It is out of context: the beginner section only covers incredibly simple imperative programming. This challenge is perfectly doable (if difficult) with only the imperative programming techniques that have already been introduced: however the test will fail if you try to do that (this is a bug, but it’s an extremely bad bug in this case).
The concepts introduced abruptly in the ES6 section are actually introduced in a much steadier way in later sections - for this one, if it came at the end of the functional section, the description could literally just say ‘you can make your code terse using arrow functions, here’s an example’ and it would make sense.