<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/steamroller#?solution=var%20result%20%3D%20%5B%5D%3B%0Afunction%20steamrollArray%28arr%29%20%7B%0A%20%20%2F%2F%20I'm%20a%20steamroller%2C%20baby%0A%20%20for%28var%20i%20%3D%200%3B%20i%3Carr.length%3B%20i%2B%2B%29%0A%20%20%20%20%7B%0A%20%20%20%20%20%20if%28Array.isArray%28arr%5Bi%5D%29%29%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20steamrollArray%28arr%5Bi%5D%29%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20else%20if%28!Array.isArray%28arr%5Bi%5D%29%20%26%26%20arr%5Bi%5D%20!%3D%3D%20null%29%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20result.push%28arr%5Bi%5D%29%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20return%20result%3B%0A%7D%0A%0AsteamrollArray%28%5B1%2C%20%7B%7D%2C%20%5B3%2C%20%5B%5B4%5D%5D%5D%5D%29%3B%0A" rel="nofollow">Steamroller</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">My code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var result = [];
function steamrollArray(arr) {
  // I'm a steamroller, baby
  for(var i = 0; i&lt;arr.length; i++)
    {
      if(Array.isArray(arr[i]))
        {
          steamrollArray(arr[i]);
        }
      else if(!Array.isArray(arr[i]) &amp;&amp; arr[i] !== null)
        { 
          result.push(arr[i]);
        }
    }
  return result;
}

steamrollArray([1, {}, [3, [[4]]]]);
"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-k">function</span> <span class="pl-en">steamrollArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// I'm a steamroller, baby</span>
  <span class="pl-k">for</span><span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">&lt;</span><span class="pl-s1">arr</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">++</span><span class="pl-kos">)</span>
    <span class="pl-kos">{</span>
      <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-v">Array</span><span class="pl-kos">.</span><span class="pl-en">isArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
        <span class="pl-kos">{</span>
          <span class="pl-en">steamrollArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-k">else</span> <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-v">Array</span><span class="pl-kos">.</span><span class="pl-en">isArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span> <span class="pl-c1">!==</span> <span class="pl-c1">null</span><span class="pl-kos">)</span>
        <span class="pl-kos">{</span> 
          <span class="pl-s1">result</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
  <span class="pl-k">return</span> <span class="pl-s1">result</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">steamrollArray</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-kos">[</span><span class="pl-c1">4</span><span class="pl-kos">]</span><span class="pl-kos">]</span><span class="pl-kos">]</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h4 dir="auto">Challenge Name</h4>

<p dir="auto">Mainly JavaScript challenges</p>
<h4 dir="auto">Issue Description</h4>

<p dir="auto">We've had many coding issues made on GitHub (a list of some from the past few months: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="163600609" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/9532" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/9532/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/9532">#9532</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="160217089" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/9137" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/9137/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/9137">#9137</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="159891587" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/9118" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/9118/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/9118">#9118</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="158433844" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/8940" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/8940/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/8940">#8940</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="159492002" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/9058" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/9058/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/9058">#9058</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="152881272" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/8436" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/8436/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/8436">#8436</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="150636738" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/8266" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/8266/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/8266">#8266</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="148879419" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/8156" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/8156/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/8156">#8156</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="148062631" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/8092" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/8092/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/8092">#8092</a> [comment within this issue], <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="142091010" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7655" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7655/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7655">#7655</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="138860379" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7441" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7441/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7441">#7441</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="142057158" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7629" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7629/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7629">#7629</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="139386806" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7470" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7470/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7470">#7470</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="139065109" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7453" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7453/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7453">#7453</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="138873931" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/7442" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/7442/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/7442">#7442</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="122093245" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/5290" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/5290/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/5290">#5290</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="119586186" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/4819" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/4819/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/4819">#4819</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="119054058" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/4733" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/4733/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/4733">#4733</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="118604482" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/4686" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/4686/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/4686">#4686</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="115240930" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/4187" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/4187/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/4187">#4187</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="111610389" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/3755" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/3755/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/3755">#3755</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="96227595" data-permission-text="Title is private" data-url="https://github.com/freeCodeCamp/freeCodeCamp/issues/1345" data-hovercard-type="issue" data-hovercard-url="/freeCodeCamp/freeCodeCamp/issues/1345/hovercard" href="https://github.com/freeCodeCamp/freeCodeCamp/issues/1345">#1345</a>) on why their code doesn't work, which turn out to be because they have a global variable they mutate with their function.</p>
<h4 dir="auto">Proposed Fix (Updated)</h4>
<p dir="auto"><del>Somewhere early in the JavaScript challenges have a note on how the tests work, in that they will only run your function and any global variables mutated in the process will keep their state.</del></p>
<ul dir="auto">
<li>Detect unsafe global variable code and wrap them in isolated blocked scope.</li>
<li>Display a notification in such cases if applicable and tests fail to run.</li>
</ul>
<p dir="auto">cc/ <a class="team-mention js-team-mention notranslate" data-error-text="Failed to load team members" data-id="1720971" data-permission-text="Team members are private" data-url="/orgs/freeCodeCamp/teams/moderators/members" data-hovercard-type="team" data-hovercard-url="/orgs/freeCodeCamp/teams/moderators/hovercard" href="https://github.com/orgs/freeCodeCamp/teams/moderators">@freeCodeCamp/moderators</a></p>