freeCodeCamp: Seek and Destroy Algorithm System Bug
Challenge Seek and Destroy has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function isequal(value) {
return value !== this;}
function destroyer(arr) {
filtered = arguments[0];
for (i=1; i<arguments.length; i++){
filtered = filtered.filter(isequal,arguments[i]);
}
return filtered;
}
destroyer([1, 2, 3, 1, 2, 3], 1);
Although my code above returns all the correct output and passes all the tests, the system will not let me proceed to the next challenge. It marks all the tests as failed. Seems to be a bug.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 33 (20 by maintainers)
Just went through, the thread, I think this should be closed as an edge case with the camper’s code. I agree detecting such code is costly, and adding any instructions will cause confusion to users.
Closing. Feel free to continue the discussion or re-open, but in my honest opinion, this should be left as it is.
One other solution I just found is to change the comparative operator from
!==to!=If you are not using a strict comparison operator it will work.@parisclinkscales
I looked at your code, and this is the fix:
@systimotic @parisclinkscales @Bouncey This is an easy-to-read solution:
And cleaner solution:
I’ve delved into this issue a bit more. Going from @elisecode247’s and @kevcomedia’s findings, here’s what I found. The second argument of
Array.prototype.filteris the optionalthisArg. If you pass an object, it will setthisinside the callback. Without'use strict';, this can only be an object. If what’s passed as thethisArgisn’t an object, it will setthisto an empty object. With'use strict;',thisis no longer forced to be an object. It can now be set to a number. My source is Elise’s MDN article, a bit further down. @Bouncey I think this issue can be closed, as it was a code problem (a difficult one though). I’d love to hear your thoughts though. Maybe the description should be altered in some way to make people aware of this problem.I want to work on this.
Check this out. It turns out
isequalchangesarguments[i]into a Number object, so thevalue !== thismeansvalueis compared to an object, and so it always returnstrue.So the campers test case is running twice?
I logged
valueandthisinisEqualand that seemed fine.@BKinahan as for your
Result:¯\_(ツ)_/¯that’s just weird