Freecodecamp: ES6: Use the Spread Operator to Evaluate Arrays In-Place

Created on 24 Sep 2020  路  4Comments  路  Source: freeCodeCamp/freeCodeCamp


Describe your problem and how to reproduce it:
In the challenge that I mentioned in the title there is an issue. Even when the output doesn't match with the challenge requirements but it still passes the challenge. I have linked some gifs so it is more understandable.

Add a Link to the page with the problem:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place

Tell us about your browser and operating system:

  • Browser Name: Google Chrome
  • Browser Version: 85.0.4183.121
  • Operating System: Windows 10 64-bit

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):
The output doesn't match with the requirements but it still passes the challenge:
https://gyazo.com/f27f86327cd9dc9d5959c2dc456f1041

While this is the correct code and output:
https://gyazo.com/0d11507fed0226112f059f45c0e5b97f

This also passes the challenge:
https://gyazo.com/2e3ae5310e4b638b0156ffc174b2e155

first timers only learn

Most helpful comment

Good catch!

The first test on this page uses:

assert(arr2.every((v, i) => v === arr1[i]));

A fun quirk with .every() that I ran in to yesterday is that it returns true on an empty array. This error could likely be fixed by adding an assertion for arr2.length.

All 4 comments

Good catch!

The first test on this page uses:

assert(arr2.every((v, i) => v === arr1[i]));

A fun quirk with .every() that I ran in to yesterday is that it returns true on an empty array. This error could likely be fixed by adding an assertion for arr2.length.

Good catch!

The first test on this page uses:

assert(arr2.every((v, i) => v === arr1[i]));

A fun quirk with .every() that I ran in to yesterday is that it _returns true_ on an empty array. This error could likely be fixed by adding an assertion for arr2.length.

Honestly I didn't know why it passed the challenge. Thank you for the explanation.

Opening this up for contributions. As @nhcarrigan mentions, we just need an additional condition in the assert to test that arr2.length is non-zero (which means it would be truthy).

you can find in stackovervlow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaphnisM picture DaphnisM  路  3Comments

jurijuri picture jurijuri  路  3Comments

imhuyqn picture imhuyqn  路  3Comments

MichaelLeeHobbs picture MichaelLeeHobbs  路  3Comments

raisedadead picture raisedadead  路  3Comments