question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running code in isolation, when global declarations are used

See original GitHub issue

Challenge Name

Steamroller in Intermediate Algorithm Scripting

Issue Description

I used a recursive function to complete this challenge and when tested the called challenge function returns the correct value but my challenge is not marked as completed and the tests do not pass.

Browser Information

Chrome Version 65.0.3325.146 (Official Build) (64-bit) on Windows 10 x64 (Desktop)

  • Browser Name, Version:
  • Operating System:
  • Mobile, Desktop, or Tablet:

Your Code


var newArr = [];

function testArr(item){
  if (Array.isArray(item)) {
    for (let i = 0; i < item.length; i++) {
      testArr(item[i]);
    }
  } else { 
    newArr.push(item);
  }
}

function steamrollArray(arr) {
  // I'm a steamroller, baby
  for (let i = 0; i < arr.length; i++){
    testArr(arr[i]);
  }
  return newArr;
}

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


Screenshot

2018-03-12 2018-03-12 1 2018-03-12 2 2018-03-12 3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
raisedadeadcommented, Mar 12, 2018

Yes, this is a platform limitation with use of global methods. While its also not recommended to use globals, I understand that this intent is not very clear.

The tests are not run in isolation, and hence the last value of your globals persist, breaking them.

We of course can’t make any changes, to the current production at freeCodeCamp.org, however we should discuss the possibility of at least making the intent known in some form on beta.

Same challenge on beta, for reference debugging: https://beta.freecodecamp.org/en/challenges/intermediate-algorithm-scripting/steamroller Originally reported in https://github.com/freeCodeCamp/freeCodeCamp/issues/9063

0reactions
QuincyLarsoncommented, Jun 3, 2018

I’m closing this issue as stale since it hasn’t been active lately. If you think this is still relevant to the newly updated platform, please explain why, then reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to properly isolate your code using Anonymous Closures ...
Variables declared inside the closure are not accessible outside it, but it still can access/create global variables. (The use of global ...
Read more >
Script Isolation - AutoControl
An AutoControl script and the page's own code run in different global contexts. ... runInPageCtx can be used to pass variables from one...
Read more >
nodeJS make code run in isolated vm context Or ...
Code that I will run on VM in the isolated context ... somehow create a global variable that will live only in the...
Read more >
Isolating Extension Modules
Abstract: Traditionally, state belonging to Python extension modules was kept in C static variables, which have process-wide scope.
Read more >
Guide for running C# Azure Functions in an isolated worker ...
Learn how to use a .NET isolated worker process to run your C# functions in Azure, which supports non-LTS versions of .NET and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found