Good morning coders!
I wanted to know, if anyone sees any problems with the following code? It´s for the steamroller algorithm and it´s working. The tests just don´t accept it.
I know, the code is quite ugly, but that´s javascript. In a stricter language, like C++, i could have implemented the algorithm similar, except “steamrolledArr” would have been some static attribute of the static class containing the method…
I guess i will just have to write another piece of code which passes the test. Dang it.
My code so far
function steamrollArray(arr) {
if (!Array.isArray(arr)) {
steamrolledArr.push(arr);
return;
}
for (var i = 0; i < arr.length; i++) {
steamrollArray(arr[i]);
}
return steamrolledArr;
}
var steamrolledArr = [];
steamrollArray([[["a"]], [["b"]]]);
Maybe someone finds the reason why the tests dont accept the code.
Thanks in advance.
P. S: Excuse my english.