Conte-nos o que está acontecendo:
Descreva detalhadamente o problema aqui.
**Seu código até o momento**
// A variável global
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
function add( bookList, bookName ) {
let bookListCopy = bookList.slice(0);
bookListCopy.push( bookName );
return bookListCopy;
};
function remove( bookList, bookName ) {
let bookListCopy = bookList.slice(0);
if( bookListCopy.indexOf( bookName ) >= 0 ) {
bookListCopy.splice( bookListCopy.indexOf( bookName ), 1 );
return bookListCopy;
}
};
porem , eu fiz outro codigo e acho que tive resultado parecidos , olha :
'The Hound of the Baskervilles',
'On The Electrodynamics of Moving Bodies',
'Philosophiæ Naturalis Principia Mathematica',
'Disquisitiones Arithmeticae',
];
const [bookOne, bookTwo, bookThree, ...otherBooks] = bookList;
console.log(`esta é a lenght de bookList : ${bookList.length}`);
console.log(bookList);
function add(bookName) {
const addBooks = bookList;
addBooks.push(bookName);
return addBooks;
}
function remove(bookName) {
const removeBooks = bookList;
const book_index = removeBooks.indexOf(bookName);
if (book_index >= 0) {
removeBooks.splice(book_index, 1);
return removeBooks;
}
}
const adding = add(bookOne);
console.log(adding);
const removing = remove(bookThree);
console.log(removing);
o que vcs acham ???
**Informações de seu navegador:**
Agente de usuário: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Desafio: Programação Funcional - Refatorar variáveis globais fora de funções
Link para o desafio: