Create a Deep Flattening Tool - Create a Deep Flattening Tool

Tell us what’s happening:

I was able to pass all the tests. I’m just wondering if this would be considered hard coding for the tests? If you believe it is, could you give me some hints on directions to go so that the code would be more universal.

Thanks!

Your code so far

function steamrollArray (arr) {
  let newArr = [];
  const arrTest = (arg) => {
    if (Array.isArray(arg) && Array.isArray(arg[0])) {
      arrTest(arg[0]);
    } else {
      for (let j = 0; j < arg.length; j++) {
        if (Array.isArray(arg[j])) {
          arrTest(arg[j]);
        } else {
          newArr.push(arg[j]);
        };
      };
    };
  };
  for (let i = 0; i < arr.length; i++) {
    if (!Array.isArray(arr[i])) {
      newArr.push(arr[i]);
    } else {
      arrTest(arr[i]);
    }
  };
  return newArr
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Create a Deep Flattening Tool - Create a Deep Flattening Tool

Welcome back @suphxx ,

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

The category of this topic has also been changed to “Code Feedback”.

Happy coding!