-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefactorGlobalVariablesOutofFunctions.js
More file actions
35 lines (26 loc) · 1.14 KB
/
refactorGlobalVariablesOutofFunctions.js
File metadata and controls
35 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 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 (arr,bookName) {
let emtyarr = [...arr];
emtyarr.push(bookName);
return emtyarr;
// 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 (arr,bookName) {
let emtyarr = [...arr];
if (emtyarr.indexOf(bookName) >= 0) {
emtyarr.splice(emtyarr.indexOf(bookName),1);
return emtyarr;
// Add your code above this line
}
}
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);