Skip to content

Commit 859f097

Browse files
committed
mouredev#23 - JavaScript
1 parent 7ab4710 commit 859f097

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Roadmap/03 - ESTRUCTURAS DE DATOS/javascript/RicJDev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function eliminaContato() {
228228

229229
function muestraOpciones() {
230230
rl.question(
231-
'\nElige una opcion:\n1.Insertar contacto (i)\n2.Buscar contacto (b)\n3.Actualiar contacto (a)\n4.Eliminar contacto (e)\n5. Mostrar lista de contactos (m)\n6.Salir (s)\n',
231+
'\nElige una opcion:\n1.Insertar contacto (i)\n2.Buscar contacto (b)\n3.Actualiar contacto (a)\n4.Eliminar contacto (e)\n5.Mostrar lista de contactos (m)\n6.Salir (s)\n',
232232
(answer) => {
233233
answer = answer.toLowerCase();
234234

Roadmap/23 - SINGLETON/javascript/RicJDev.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ console.log(anotherVillain.name);
2020

2121
//EXTRA
2222
class UserSession {
23+
app = 'Ric-JS-Sandbox';
24+
25+
user = {
26+
instances: 0,
27+
};
28+
2329
constructor() {
2430
if (typeof UserSession.instance === 'object') {
2531
return UserSession.instance;
@@ -28,4 +34,51 @@ class UserSession {
2834
UserSession.instance = this;
2935
return this;
3036
}
37+
38+
init(name, username, userID, email) {
39+
if (this.user.instances === 0) {
40+
this.user.name = name;
41+
this.user.username = username;
42+
this.user.userID = userID;
43+
this.user.email = email;
44+
this.user.instances++;
45+
return this.user;
46+
}
47+
}
48+
49+
getData() {
50+
let result = [];
51+
Object.keys(this.user).forEach((element) => {
52+
result.push(this.user[element]);
53+
});
54+
return result;
55+
}
56+
57+
close() {
58+
return (this.user = {
59+
instances: 0,
60+
});
61+
}
3162
}
63+
64+
let session = new UserSession();
65+
66+
console.log(session);
67+
68+
console.log(session.getData());
69+
70+
session.init('Fred', 'CrazyFred4564', 7880003, 'crazyfred@gmail.com');
71+
72+
console.log(session);
73+
74+
session.close();
75+
76+
console.log(session.getData());
77+
78+
session.init('Fred', 'CrazyFred4564', 7880003, 'crazyfred@gmail.com');
79+
80+
console.log(session.getData());
81+
82+
session.init('Sarah', 'SunshineSarah2435', 6550099, 'sarahmilanesa@gmail.com');
83+
84+
console.log(session.getData());

0 commit comments

Comments
 (0)