Tell us what’s happening:
I dont know whats happening, that’s the problem. When did we go through reduce
, map
or filter
?
i tried looking online and on youtube and got many explanation to what a spread operator is, which is basically a way to take in the elements of an array into the arguments of a function using ...args
.
Ill explain what i know so far. The code declares a constant variable named sum, which will be an expression function.
I don’t really understand what "use strict"
means because we were told to ignore it in previous lessons.
return function sum(x, y, z)
?! - Is this an expression function or what type of function is this exactly ?
const args = [x, y, z];
- This is declaring a constant array with the variables of the function sum parameters.
return args.reduce((a,b) => a+b, 0);
- This is an arrow functions that has 2 parameters, a and b and adds them together to result in a sum which is then given like so, - sum, 0
.
To be honest, im really thinking hard about ditching freeCodeCamp. The whole site is amazingly designed but i really am starting to think the curriculum isn’t the best. Im constantly being presented with things i have to search up and learn by myself. Its assuming that we know some things already when we are truly beginners. Im sorry for the ranting, but it has been going on a lot.
Thanks for the support, i am still looking to finish at least the ES6 part of this curriculum.
Your code so far
const sum = (function() {
"use strict";
return function sum(x, y, z) {
const args = [ x, y, z ];
return args.reduce((a, b) => a + b, 0);
};
})();
console.log(sum(1, 2, 3)); // 6
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-rest-operator-with-function-parameters