# Intermediate Algorithm Scripting: Steamroller: I tried solving this problem with somewhat of recursion

**URL:** <https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-i-tried-solving-this-problem-with-somewhat-of-recursion/444099>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 3, 2021, 4:34am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-i-tried-solving-this-problem-with-somewhat-of-recursion/444099 "2021-02-03T04:34:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yacoub05](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/yacoub05/32/199853_2.png) [@yacoub05](https://forum.freecodecamp.org/u/yacoub05)\
**Post date:** [February 3, 2021, 4:34am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-i-tried-solving-this-problem-with-somewhat-of-recursion/444099/1 "2021-02-03T04:34:19Z")

</div>

**Tell us what’s happening:**

i tried solving this problem with recursion however i dont know if what i am doing is the correct way or if i am missing something it seems like i am close.

**Your code so far**

```js

function steamrollArray(arr) {
let obj = []
let element

    if(!Array.isArray(arr)){
      element = arr
        
        return element
     }
    else if(arr == '[object Object]'){
    return JSON.stringify('{}')

    }

   else if(Array.isArray(arr) ){
      
      arr.map(item=>{
      
      obj.push(steamrollArray(item))

    })

}
console.log(obj)

}

steamrollArray([1, {}, [3, [{},[4]]]]);

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36`.

**Challenge:** Steamroller

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [February 3, 2021, 7:28am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-i-tried-solving-this-problem-with-somewhat-of-recursion/444099/2 "2021-02-03T07:28:30Z")

</div>

Generally it’s possible to do this with recursion, yes. As with recursion what need to be considered is an appropriate base case, and way recursive calls are made otherwise to get closer to the base case.

Notice that right now function not in every case is returning something, hence the `undefined` that can be observed in result.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 4, 2021, 7:28pm UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-i-tried-solving-this-problem-with-somewhat-of-recursion/444099/3 "2021-08-04T19:28:57Z")

</div>

Closed on August 4, 2021, 7:28pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
