Broken Test - Refactor Global Variables Out of Functions in JS curriculum
See original GitHub issueAffected page
Your code
// The global variable
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
// Change code below this line
function add(bookList, bookName) {
return [...bookList, bookName]
// Change code above this line
}
// Change code below this line
function remove(bookList, bookName) {
const book_index = bookList.indexOf(bookName);
if (book_index >= 0) {
bookList.splice(book_index, 1);
return bookList;
// Change code above this line
}
}
// console.log(bookList)
// console.log(remove(bookList, "The Hound of the Baskervilles"))
// console.log(bookList)
Expected behavior
Test shouldn’t accept this answer as bookList was modified
System
- Device: MacBookPro11,5
- OS: MacOS 11.6.1
- Browser: Chrome
- Version: Version 99.0.4844.51 (Official Build) (x86_64)
Request
I’m new around here and this is my first contribution to FCC. If appropriate I would like to try and fix this bug
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Refactor Global Variables Out of Functions - Free Code Camp
In this functional programming tutorial we refactor global variables out of functions. This video constitutes one part of many where I cover ...
Read more >About the Refactor Global Variables Out of Functions
If any step requires more steps, then I break it down further. But none of these do. 1. the global array bookList is...
Read more >Avoiding mutable global state in browser JS | by Josh Wulf
Any local function can mess with the functioning of any other function by mutating global scope, and this can result in bugs that...
Read more >How do I deal with global variables in existing legacy code (or ...
Have a careful look at these globals and firstly work out if they should be global. If there is no clear reason, any...
Read more >Question: Do you use $GLOBALS or not? : r/PHP - Reddit
That means from the outside, Foo is much harder to use, test, refactor and ... pass some PHP variables from the server 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
Thanks for reporting this issue. I agree with Jeremy that addressing the global state issue still needs to be done. However, this specific issue can be fixed independently.
We do have a test which checks that the
bookList
array is unmodified, but it only tests theadd
function and not theremove
function. IMHO, it would be sufficient to add aremove
call in that first test.I am sorry @csabsen, I just saw you’re still interested in fixing this issue. I can close my PR, so that you can fix the issue yourself. Let me know if that is what you want.