Create a Deep Flattening Tool - Create a Deep Flattening Tool

Tell us what’s happening:

How can I split this thing to get the result
Because when I convert {} to a string it returns [object object]

Your code so far

function steamrollArray(array){
  let numbers = "1234567890"
  let newArr = []
  for(let name of array){
   if(!Array.isArray(name)){
   name = JSON.stringify(name)
   }
   newArr.push(name)
  }
  let arr = newArr.reduce((prev, next) => {
   return prev + next
  }, "").replaceAll(",","")
  let value = arr.split("")
  for(let i = 0; i < value.length; i++){
  if(numbers.includes(value[i])){
   value[i] = Number(value[i])
  }
  }
  return arr
  
}
console.log(steamrollArray([1, {}, [3, [[4]]]]))

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Mobile Safari/537.36

Challenge Information:

Create a Deep Flattening Tool - Create a Deep Flattening Tool

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-deep-flattening-tool/ab306dbdcc907c7ddfc30830.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @Richmond_otache,

You might want to look into using recursion for this challenge. That way, when you loop over the nested array, you only need to check whether an item is an array — if it is, you call the function again — if it isn’t, you push the item into the final array that will be returned.

Happy coding