-
Notifications
You must be signed in to change notification settings - Fork 1
/
12-7-Person.js
56 lines (48 loc) Β· 1003 Bytes
/
12-7-Person.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* p496 μμ
*/
class Person {
#name;
#genderCode;
constructor(name, genderCode) {
this.#name = name;
this.#genderCode = genderCode;
}
get name() {
return this.#name;
}
get genderCode() {
return this.#genderCode;
}
get isMale() {
return "M" === this.#genderCode;
}
// μλ΅
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const data = [
{ name: "λ§ν΄ νμΈλ¬", gender: "M" },
{ name: "λ λ² μΉ΄ νμ¨μ€", gender: "F" },
{ name: "리ν©ν°λ§" },
];
const people = loadFromInput(data);
/**
* μμ νΈμΆ
*/
function createPerson(aRecord) {
switch (aRecord.gender) {
case "M":
return new Person(aRecord.name, "M");
case "F":
return new Person(aRecord.name, "F");
default:
return new Person(aRecord.name, "X");
}
}
function loadFromInput(data) {
return data.map((aRecord) => createPerson(aRecord));
}
const numberOfMales = people.filter((p) => p.isMale).length;
console.log(numberOfMales);