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: