Bug in challenge

This challenge has a bug in it.

This should work:

const dropElements = (arr, func) => {
  get_remaining_elements = false;
  return arr.reduce((a, b) => {
      get_remaining_elements = get_remaining_elements ? true : func(b);
      return get_remaining_elements ? [...a, b] : a;
  }, []);

But I get:

Which is clearly wrong.

Do you need to add let?

Using let is more accurate, but not required.

FCC is essentially using ‘use strict’ so I think you need it. It’s good practice anyway.

You’d think FCC would enforce what Chrome implements in their browsers.

While we’re on good practices, camel case is standard for variable names in JavaScript.
This ain’t Ruby or Python.

See the discussion here

I’m a full-time senior developer. I’m well aware what coding standards are. Ultimately the job dictates that.

I’m just saying,. it’s valid code.

It’s not valid code in strict mode, that’s the point. You can read more here:

I would hope that you’d reject valid yet sloppy code that doesn’t conform to standards during code review.

1 Like

Sure. It’s just not valid for the requirements of the FCC environment.

Then the coding challenges should have 'use strict'; displayed in the function and not on some obscured page.

Nevertheless it’s uncommon for any job to have their programmers add ‘use strict’ in their code.

I don’t agree that it’s uncommon to do so, mostly because people aren’t usually writing raw JavaScript that isn’t transformed through a build tool (which would likely fail to compile your example), or that isn’t analyzed by ESLint (which would display an error at the variable declaration without let).

If you don’t want to declare your variables with a keyword that badly, then why don’t you just use a different language and transpile to JavaScript? Maybe that would be easier for you.

1 Like

It’s considered a best practice to declare your variables.

You’re missing point. Bad vs Valid.

‘use strict’; is not there. It should work. FCC has it added in global space unknown to user. One the most important lessons you can learn is understanding what you call bad code. People usually get hired to fix legacy code. If a user was faced with a global variable situation where they did not have the luxury to modify it without redoing the entire script, they need to know how it works. And when the environment doesn’t inform us that there is ‘use strict’ is being used (which should be shown at top of function) it’s misleading. The code example I wrote is to demonstrate the flaw & not my own practices.

The use of ‘use strict’ is discussed in the curriculum. The reasons for it being a requirement in the FCC environment are discussed in the link I provided. If you strongly believe that making this a default that students cannot bypass is an error, you can log an issue on the FCC GitHub repo.