Running code in isolation, when global declarations are used
See original GitHub issueChallenge 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
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.