Flawed Solution: Intermediate Algorithm Scripting

I think that the Solution 3 of freeCodeCamp Challenge Guide: Steamroller is flawed, the flaw is in parseInt() so, if i have a float it will turn it to an integer, thus, it should fail the test of the challenge, but it does pass it, and it is considered a solution, but i don’t think it should be a solution…

The code of the solution below:

Solution 3
function steamrollArray(arr) {
  return arr
    .toString()
    .replace(",,", ",") // "1,2,,3" => "1,2,3"
    .split(",") // ['1','2','3']
    .map(function(v) {
      if (v == "[object Object]") {
        // bring back empty objects
        return {};
      } else if (isNaN(v)) {
        // if not a number (string)
        return v;
      } else {
        return parseInt(v); // if a number in a string, convert it
      }
    });
}

The link to the challenge:

Hello there,

I am not sure I understand the issue; the solution passes the tests, and accomplishes the challenge. Yes, there are inputs which would return unexpected results, however, almost all of the solutions operate this way - they are not made to be production-ready code.

1 Like