[Arguments Optional] Current test cases allow for unintended solutions to pass
See original GitHub issueDescribe your problem and how to reproduce it:
On the Intermediate Algorithm Scripting: Arguments Optional challenge, the only two happy path test cases – addTogether(2, 3)
and addTogether(2)(3)
, both expect a return value of 5. All other test cases expect a return value of undefined. Because there are no other happy path test cases, it’s possible to construct a passing solution that doesn’t add inputs together, but simply returns 5 when the inputs are valid numbers (pasted below). Another set of happy path test cases could help prevent this sort of unintended solution from passing.
// passes tests without performing addition
function addTogether(x, y) {
if (y) {
return returnFive(x, y);
}
return curriedReturnFive(x);
}
function returnFive(x, y) {
if (!areNumbers(x, y)) {
return;
}
return 5; // just 5 satisfies current tests
}
function curriedReturnFive(x) {
if (!isNumber(x)) {
return;
}
return function(y) {
return returnFive(x, y);
}
}
function areNumbers(...args) {
return args.every(isNumber);
}
function isNumber(x) {
return typeof x === 'number';
}
Add a Link to the page with the problem: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional
If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (16 by maintainers)
Top GitHub Comments
Hi @Ieahleen @moT01 @Sky020 , I hope you’re good. I have raised a PR for this Issue with adding 2 extra test cases. Let me know if more test cases are to be added or something is not right. Thanks a lot guys for the opportunity.
@Sky020 - Please allow me to work on this. I am new to open source and it would be great If I can work on this .