Functional Programming - Refactor Global Variables Out of Functions

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

Even though the function remove is correct but still its not passing the test, kindly help on this

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(arr,bookName) {

  arr.push(bookName);
  return arr;
  
  // Change code above this line
}

// Change code below this line
function remove(arr,bookName) {
  const book_index = arr.indexOf(bookName);
  if (book_index >= 0) {

    arr.splice(book_index,1);
    console.log(arr)
    return arr;

    // 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/113.0.0.0 Safari/537.36

Challenge: Functional Programming - Refactor Global Variables Out of Functions

Link to the challenge:

You are modifying arr. The challenge wants you to make a brand new copy of arr before you modify it in your functions.

Hi There

Thanks for your quick response, I tried copying array value to a temp variable but still it didn’t working:

function remove(arr,bookName) {
 let newArr=arr
 const book_index = newArr.indexOf(bookName);
  if (book_index >= 0) {

    newArr.splice(book_index,1);
    
    return newArr;

    // Change code above this line
    }

Review some of the previous challenges in this block - this line does not make a copy