-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
38 lines (31 loc) · 1.26 KB
/
data.js
File metadata and controls
38 lines (31 loc) · 1.26 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
36
37
export let guitars = [
{ model: "les paul", make: "gibson", type: "electric solid archtop", year: 1952 },
{ model: "telecaster", make: "fender", type: "electric solid body", year: 1954 },
{ model: "330", make: "rickenbacker", type: "electric semi-hollow body", year: 1958 },
{ model: "casino", make: "epiphone", type: "electric hollow body archtop", year: 1961 },
{ model: "phantom", make: "vox", type: "electric hollow body", year: 1963 },
];
const getAll = () => {
return guitars;
}
const getItem = (model) => {
return guitars.find((guitar) => {
return guitar.model === model;
});
}
const addItem = (addGuitar) => {
const guitarList = guitars.length;
let found = getItem(addGuitar.model);
if (!found) {
guitars.push(addGuitar);
}
return { added: guitarList !== guitars.length, total: guitars.length };
};
const deleteItem = (model) => {
const guitarList = guitars.length;
guitars = guitars.filter((item) => {
return item.model !== model;
});
return { deleted: guitarList !== guitars.length, total: guitars.length };
};
export { getAll, getItem, addItem, deleteItem };