So i’m tired of debating back and fourth with a person about this issue, in which its just getting nowhere. I want to see who and what idea is truly right as i want to continue learning ES6, but the supposed correct way.
So this is the challenge → https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions
I saw the challenge and did it in the simplest way possible:
const sum = (...args) => {
return args.length > 0 ? args.reduce((num, i) => num+=i) : 0
// num is accumulator, i is the number.
}
Used the simplest format, ES6, and the rest operator. It gets the job done and its readable.
Now the challenge doesn’t let me pass because its saying i didn’t even use the rest operator, and the explanation i got was saying their is only one way of formatting it:
const sum = (function () {
const sum = (...args) => {
return args.length > 0 ? args.reduce((num, i) => num+=i) : 0
}
return sum;
})();
Both return the exact same thing → ES6 #10 - Use the rest operator - Replit
When i see this, i observe it as not simplified, unnecessary, and hard to read. I stand by my code and both answers to the challenges as they are both correct, but don’t stand by my code not passing.
Of course there is maybe a reason why adding the extra unnecessary function helps with some cases, but if you look just at this challenges its simply not needed.
Lets take a look at older challenges:
Trying to teach arrow functions they give you this:
var magic = function() {
"use strict";
return new Date();
};
…And ask you to first do arrow code, also to change var
to const
Yes the purpose is to teach you arrow code functions, but its a bad example as it can easily be changed to:
var magic = new Date()
The potential answers to this, and other challenges start vary way to much as you get higher up complication wise, as some people just see it as what is the simplest way to accomplish the end result regardless of wanted format, because good code is simple and readable.
I don’t code by one format, i code by whats best. Not all challenges are even the same, so living by the potentially least best way possible is not my path.
Its like using loop(s) to reverse a array, instead of cutting the corner and just using .reverse()
. Some people would use the loop as wanted, but some see a different less complicated way that makes sense for this issue.
When you run a function, you see its output, so the simplest way to get their is the correct way. You don’t see what its doing, only the end result.
In context here, its completely unnecessary to have a function over a function for something like this as their is better ways to do it with the same output. It’s trying to teach me the supposed way, but you can get confused and do it the other more logical way since their is nothing preventing you (because of the openness of the challenges).
I was met with:
When the fact that this is student paced, and i’m here because i want to be.
This is new curriculum, and if it isn’t working i’m going to say something about it. I came from ES5 to ES6 for simpler, less complicated code. I don’t see doing everything in a format, rather whats the best way to accomplish the end goal.
No need to code to specification, since their is really is none at this small of a level. Do you think a employer really cares to go back and pay you $40 a hour to edit all of your already simple readable working code just to add unnecessary functions for ‘tradition’? No, because in all reality they really don’t care. They care you get the job done in the simplest way possible, like the output.
If you can read unnecessary complicated code, you can read simple code too.
You can travel down point A & B to get to a place, but you can also go down the hypotenuse. Both are correct, one is shorter.
6+3 = 9
5+4 = 9
There is varying ways to do things, have a open mind with my topic.
What am i missing here?
If i have to deal with functions inside of functions for the sum of a input because its ‘ES6 traditional’ format, then i’m done here.