The solution:
function thingsToBuy() {
var list = [
"milk",
"bread",
"bananas"
];
return {
removeItem: function(name) {
list = list.filter(item => item !== name);
return list;
},
addItem: function(item) {
list.push(item);
return list;
},
getList: function() {
return list;
}
};
}
This is a basic exercise to see if you understand how JS works.
The function gives you some methods to mutate the list variable. You should read more about Array.filter, Array.push to see their input and output.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…