NovichokJS,
class User {
constructor(id, name, sessionId) {
this.id = id;
this.name = name;
this.sessionId = sessionId;
}
}
class UserRepository {
users = [];
constructor(users) {
this.users.push(...users);
}
getUserNames() {
return this.users.map(({name}) => name);
}
getUserIds() {
return this.users.map(({id}) => id);
}
getUserNameById() {
return this.users.map(({sessionId}) => sessionId);
}
}
// examples
const user = new User('1', 'Jack', 'session-id');
const user2 = new User('2', 'Jack2', 'session-id2');
const repository = new UserRepository([user, user2]);
console.log(repository.getUserNames())