Freecodecamp: My Code is not Correct, But it passes the challenge

Created on 14 Oct 2016  路  4Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Seek and Destroy has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


function destroyer(arr) {
  // Remove all the values
  var args = Array.from(arguments);
  return args[0].filter(function(val){
    return val!=args[1] && val!=args[2] && val!=args[3];
  });
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Function destroyer will only filter elements not more than 3.
What if a total of 5 arguments are passed to the function.

first timers only help wanted

Most helpful comment

I once saw a nice talk about testing in which the speaker says about testing for

  • 0 input (or no inputs)
  • 1 input
  • 3 inputs (small number of inputs)
  • 5 inputs (small number of inputs)
  • 50 or more inputs (or similar large number of inputs)

Considering the limitation of the platform, I suggest to at least add a 8 input test.
But still as @erictleung says, one can bypass that by hard coding the cases.

All 4 comments

@harshtomar6 thanks for the issue. I agree that you are able to brute force the algorithm like your code does. I'm not sure how you would test for any number of arguments possible because you would not only add tests, but you could always write to the tests. In other words, we could add five arguments and you could modify your code to just handle five. Why not six? It seems like a slippery slope to me.

So I would say to just keep the challenge the way it is. Firstly, the challenge already has a variety of input sizes (one through three). Secondly, this challenge is only in the Basic Algorithm Scripting section. There are more difficult algorithm challenges ahead.

@FreeCodeCamp/issue-moderators second opinions?

@harshtomar6 I second @erictleung 's comments on this

I once saw a nice talk about testing in which the speaker says about testing for

  • 0 input (or no inputs)
  • 1 input
  • 3 inputs (small number of inputs)
  • 5 inputs (small number of inputs)
  • 50 or more inputs (or similar large number of inputs)

Considering the limitation of the platform, I suggest to at least add a 8 input test.
But still as @erictleung says, one can bypass that by hard coding the cases.

First-timers Only

Add another test case with a minimum of 8 inputs.

The code for this challenge is here

Reading CONTRIBUTING.md will help you set up your testing environment.

If you run in to any issues, got to the Contributiors Chat Room.

Happy Coding :+1:

Was this page helpful?
0 / 5 - 0 ratings