Functional Programming - Refactor Global Variables Out of Functions

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// 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) {

  bookList.push(bookName);
  return bookList;
  
  // 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
    }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Functional Programming - Refactor Global Variables Out of Functions

Link to the challenge:

“Rewrite the code so the global array bookList is not changed inside either function.”

function add(bookList,bookName) {
  bookList.push(bookName);
  return bookList;
}

If the global array bookList is passed into this function as the first arg, is it being changed inside of your function?

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