diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md index 0148e58505..78b3f2c02c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md @@ -14,7 +14,7 @@ Adding one to a number is not very exciting, but we can apply these principles w ## Instructions
-Rewrite the code so the global array bookList is not changed inside either function. The add function should add the given bookName to the end of an array. The remove function should remove the given bookName from an array. Both functions should return an array, and any new parameters should be added before the bookName one. +Rewrite the code so the global array bookList is not changed inside either function. The add function should add the given bookName to the end of an array. The remove function should remove the given bookName from an array. Both functions should return an array, and any new parameters should be added before the bookName parameter.
## Tests @@ -45,13 +45,14 @@ tests: 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 +// New parameters should come before bookName // Add your code below this line function add (bookName) { - return bookList.push(bookName); - + bookList.push(bookName); + return bookList; + // Add your code above this line } @@ -60,9 +61,11 @@ function add (bookName) { // Add your code below this line function remove (bookName) { - if (bookList.indexOf(bookName) >= 0) { + var book_index = bookList.indexOf(bookName); + if (book_index >= 0) { - return bookList.splice(0, 1, bookName); + bookList.splice(book_index, 1); + return bookList; // Add your code above this line }