Refactor Global Variables Out of Functions-forced to use spread operator?

Tell us what’s happening:
Tried to use slice() to make a copy of the array that’s passed in, but it just says that’s not a function. Only works when I had new array use spread operator to copy the array. I also couldn’t call indexOf on the passed-in array- same error message.

Your code so far


// the global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];

/* This function should add a book to the list and return the list */
// New parameters should come before the bookName one

// Add your code below this line
function add (books, bookName) {
  let updatedBooks = [...books];
  // can't use books.slice();
  return updatedBooks.push(bookName);
  
  // Add your code above this line
}

/* This function should remove a book from the list and return the list */
// New parameters should come before the bookName one

// Add your code below this line
function remove (books, bookName) {
  // let updatedBooks = books.slice(); says books.slice not a function?
  let updatedBooks = [...books];
  if (updatedBooks.indexOf(bookName) >= 0) {
   
    return updatedBooks.splice(updatedBooks.indexOf(bookName), 1);
    
    // Add your code above this line
    } else {return books;}
    
}

var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');

console.log(bookList);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions

The problem is with this test:
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');

Your add function is not returning an array, so you cannot slice or splice it.