Use the Rest Operator with Function Parameters - Random error?

A lot of this code has never been done before, so whose to notice format as much?

I mean the output doesn’t change, and companies aren’t going to pay people to go back and fix a couple things and their if its not broken.

Yeah it might take a millisecond less to run, but at $40 a hour its not worth telling people to double check it as much considering it already works well.

You do seem like a good coder also, i just don’t want to stick with formatting my code a set way (that is what comments are for).

Exactly. But this means there’s alot of legacy code out there that won’t be using es6. Just saying.

I dunno. Would you rather get used to this now, or later? And this is just styling, not even architectural (code structure).

Do you like that long ass function name?

From the airbnb style guide here → GitHub - airbnb/javascript: JavaScript Style Guide

Lol yeah

I do follow the basic rules of readability and maintainability, but i also have accidentally created very terrible unreadable code which has wasted a lot of my time. That is why i started to learn the shortest way to do things.

So am i going to have to follow the FCC format, like convert my code with a IIFE?

Only if it’s required. When you start a test pay attention to the structure they start you with. The way I think about it is

  • the starting structure are the architectural specs
  • the tests are the business logic specs

Sometimes you may be able to rewrite FCC’s structure as you have seen. I honestly don’t know why it seems random. You can usually get away with refactoring anything but IIFEs and classes, because those are structures they can easily test for.

You are alot like me, in that I hardly listen to how they want the code written.

I was using es6 before they switched by using the comment flag last year. But I always write to pass the tests first. And sometimes I have been forced to rewrite it differently.

Update: i tried your code today, the IIFE just trying to pass the challenge, and i still got the same error:

 "use strict"
const sum = (function () {
    const sum = (...args) => {
      return args.length > 0 ? args.reduce((num, i) => num+=i) : 0
     }
  return sum;
})();

Typo anywhere?

You don’t have a typo. That code is correct as far as keeping the data structure of the function. But I think FCC is testing explicitly for a named function sum, and since arrow functions are all anonymous, it will fail their test. Without seeing their test assertions I couldn’t say for sure.

Its just the same error as my other code, but as we discussed i feel as yours is closer,

What is the correct code than?

The correct code to pass the test? It’s this version:

const sum = (function () {
    return function sum(...args) {
      return args.length > 0 ? args.reduce((num, i) => num+=i) : 0
     }

})();

They just wanted a named function.

This fails the tests, and is why he asked the question originally. Although semantically and logically correct, my guess is the test is asserting for a named function.