Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoint: Iterate over Arrays with map accepts incorrect code after initial pass #5428

Closed
sludge256 opened this issue Dec 23, 2015 · 11 comments

Comments

@sludge256
Copy link
Contributor

Challenge Waypoint: Iterate over Arrays with map has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

After you pass the test once you can submit "incorrect" code and still pass.

Seems like a minor issue but it would affect people copying and pasting code from chat when assisting others if they have already finished this waypoint.
After some more testing though, hitting the reset button does seem to fix this but I personally usually just paste over all my old code instead of hitting reset.

My code:
First pass:

var oldArray = [1,2,3,4,5];

// Only change code below this line.

var newArray = oldArray.map(function(val) {
  return val + 3;
});

// Only change code above this line.

(function() {return newArray;})();

Second pass:

var oldArray = [1,2,3,4,5];

// Only change code below this line.

var garbage;//= oldArray.map(Math.floor);
// Only change code above this line.

(function() {return newArray;})();

On this user-agent I believe it checks for the existence and valid use of .map() while on,

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
it seems to also check for the correct array and values which can be hard-coded after initial pass.

@tenhobi
Copy link

tenhobi commented Dec 23, 2015

👍

@SaintPeter
Copy link
Member

Confirmed. I was able to do this on Chrome. Maybe the tests are stateful in some way?

@SaintPeter SaintPeter added help wanted Open for all. You do not need permission to work on these. confirmed labels Dec 23, 2015
@easher
Copy link

easher commented Dec 24, 2015

This issue isn't unique to this way point. the next waypoint
waypoint-condense-arrays-with-reduce can reproduce the same issue. Tests pass as expected here:

var array = [4,5,6,7,8];

// Only change code below this line.

var singleVal = array.reduce(function(a,b){
  return a + b;
});
// Only change code above this line.

(function() {return singleVal;})();

Then if you try this right after test passes, the reported unexpected behavior of tests passing happens here:

var array = [4,5,6,7,8];

// Only change code below this line.

//var singleVal = array.reduce(function(a,b){
 // return a + b;
//});
// Only change code above this line.

(function() {return singleVal;})()

But if you try this right after tests pass, tests still fail appropriately:

var array = [4,5,6,7,8];

// Only change code below this line.

var singleVal = array.reduce(function(a,b){
  return a - b;
});
// Only change code above this line.

(function() {return singleVal;})()

Tests also fail appropriately in the waypoint that this was reported when submitting invalid code. It appears only to be when there is no code or disabled code that produces this issue.

@natac13
Copy link
Contributor

natac13 commented Dec 24, 2015

If we declare the newArray variable in the seed code then upon removal of the code to pass the test we will get a failing test once again.

var oldArray = [1,2,3,4,5];
var newArray = [];

// Only change code below this line.

var garbage;//= oldArray.map(Math.floor);
// Only change code above this line.

(function() {return newArray;})();

The second test still passes since .map() is used in a comment. Perhaps the test for that should be changed to be a little more strict....
I would be happy to make these changes and PR them if everyone is happy with my thoughts.
Would even like to do the over twitch stream

@SaintPeter
Copy link
Member

@natac13 Absolutely. We're open to PRs to more effectively test this.

While you're at it, you can move the display function to the tail. You may need to add a "tail" to do so.

@natac13
Copy link
Contributor

natac13 commented Dec 25, 2015

@SaintPeter not exactly sure what you mean by move the display function to the tail...

@natac13
Copy link
Contributor

natac13 commented Dec 25, 2015

Understand now Thanks!

@ghost ghost removed the help wanted Open for all. You do not need permission to work on these. label May 10, 2016
@vipuldcoder
Copy link

what is the need of this >> "(function() {return newArray;})();" we also can do like this
//var newArray = oldArray.map(function(val){
val = val + 3;
return val ;
});//

@alexlo0319
Copy link

alexlo0319 commented Mar 14, 2017

Is in the example for this section but in the example it has a * sign and is + for your assignment. It says it in the requirement "add three to each value" the key word is ADD.

@knezinho
Copy link

ADD is + so when you write:
var newArray = oldArray.map(function(val) {
return val + 3;
});
console.log(newArray);
console.log(oldArray);
Result is [4,5,6,7,8] for newArray, because it ADDS 3 to each value of oldArray...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants