There appears to be a problem with the test cases, if a student were to bruteforce his way through the exercise then there's a solution that passes the tests but prints out incorrect outputs:
namedOptionalSum ({int? first, int? second, int? third}) {
var sum = 0;
if (first != null && second != null && third != null) {
sum = first + second + third;
};
if (first == null && second != null && third != null) {
sum = second + third;
};
if (second == null && first != null && third != null) {
sum = first + third;
};
if (first == null && second == null && third != null) {
sum = third;
};
return sum;
}
So with this codes all tests pass. However if we were to try this out with these values as parameters, the value should be '2' instead of '0' (which it's what it prints.
void main() {
var res = namedOptionalSum(first: null,second: 2,third: null);
print(res);
}
There appears to be a problem with the test cases, if a student were to bruteforce his way through the exercise then there's a solution that passes the tests but prints out incorrect outputs:
So with this codes all tests pass. However if we were to try this out with these values as parameters, the value should be '2' instead of '0' (which it's what it prints.