freeCodeCamp: Wrong solution is accepted when submitted

Challenge Return Largest Numbers in Arrays has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36. The code below uses map/reduce as suggested in the medium forum (I’ve reviewed the solutions over there) and is accepted when submitted.

The problem is that there is an assumption that in every subarray not all of the values are negatives and it is not shown in the description of the problem. That is, if one of the subarray contains only negatives values, the accepted solution below isn’t correct.

My code:


function largestOfFour(arr) {
  return arr.map(function(subArray) {
    return subArray.reduce(function(prev, curr) {
      return (curr > prev ? curr : prev);
    }, 0);
  });
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (18 by maintainers)

Most upvoted comments

@91aman in the future, please comment on the thread before working on the PR. @rajpatel507 looks like there is a PR in process at this point. I’m sure we’ll have more first-timer issues soon, or feel welcome to look at our issue backlog.

Wow, I’m really slacking on this issue! Thanks @91aman, I updated and tested that as well.

@91aman That was a stupid mistake, sorry. 😳 You’re absolutely right, thanks for reminding me! ❤️