Freecodecamp: Challenge [Access MultiDimensional Arrays With Indexes] Solving Bug

Created on 8 Aug 2016  ·  10Comments  ·  Source: freeCodeCamp/freeCodeCamp

Challenge Access MultiDimensional Arrays With Indexes
has an issue.

User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.
I just used myData = 4 + 4 to get myData = 8 and i solved the challenge that way, if i'm not wrong that's a bug soo...

My code:


// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];
myData = 4 + 4;

help wanted

Most helpful comment

@Pablo152 thanks for the issue. You are correct, this is a bug of sorts. Mmm to catch this kind of code, it might be difficult. We could add in two tests:

  1. The default code is var myData = myArray[0][0]; so we could check that they at least change the zeros to something else.
  2. Check that there is no myData = <some number> i.e. a regex for /myData = \d/ or something similar.

cc/ @FreeCodeCamp/issue-moderators

All 10 comments

@Pablo152 thanks for the issue. You are correct, this is a bug of sorts. Mmm to catch this kind of code, it might be difficult. We could add in two tests:

  1. The default code is var myData = myArray[0][0]; so we could check that they at least change the zeros to something else.
  2. Check that there is no myData = <some number> i.e. a regex for /myData = \d/ or something similar.

cc/ @FreeCodeCamp/issue-moderators

@erictleung One or both of those tests could be combined with the You should be using bracket notation to read the value from myArray test to avoid adding clutter to the test message area, since they target the same condition.

@erictleung I agree with @BKinahan - as we add more tests to address various corner cases that come up, we tuck these behind as few tests as possible to avoid intimidating campers with a wall of tests.

@QuincyLarson @BKinahan sounds good! I think we can just add to the You should be using bracket notation to read the value from myArray test with checking that the bracket is not myArray[0][0]. That should be sufficient to catch this corner case.

@erictleung I think we need both your test above and the aforementioned regex for /myData = \d/ because I can set myData = [2][2]; and still run the nefarious code myData = 4+4 to pass the challenge. If you agree I'll try to update the test to check for both a change of myData[0][0] and the regex.

@dhcodes sounds reasonable. As @QuincyLarson has mentioned, try to minimize the number of tests we need to add, if any. So for regex looking for /myData = \d/ wouldn't cover the case of myData = 4 + 4 so see if you can account for that as well. Thanks!

@dhcodes said he wasn't working on this, so I grabbed it up 😄

While the 4+4 solution does solve the challenge, the correct way to solve based on the directions,"using bracket notation select an element from myArray such that myData is equal to 8", would be:

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[2][1];

myArray[2][1];

nice topic that i learn,

Was this page helpful?
0 / 5 - 0 ratings