-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD
42 lines (32 loc) · 778 Bytes
/
CRUD
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
38
39
40
41
42
class Kangtoto {
constructor() {
this.games = [];
}
create(game) {
this.games.push(game);
}
read() {
return this.games;
}
update(gameId, newGame) {
for (let i = 0; i < this.games.length; i++) {
if (this.games[i].id === gameId) {
this.games[i] = newGame;
return;
}
}
}
delete(gameId) {
this.games = this.games.filter(game => game.id !== gameId);
}
}
//Instances:
const kangtoto = new Kangtoto();
// create a new game
kangtoto.create({ id: 1, name: "Super Mario Bros." });
// read all games
console.log(kangtoto.read());
// update a game
kangtoto.update(1, { id: 1, name: "Mario Kart" });
// delete a game
kangtoto.delete(1);