-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8-4-renderPerson.js
75 lines (65 loc) Β· 1.81 KB
/
8-4-renderPerson.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* p302 μμ
*/
function renderPerson(outStream, person) {
outStream.write(`<p>${person.name}</p>\n`);
renderPhoto(outStream, person.photo);
emitPhotoData(outStream, person.photo);
outStream.write(`<p>μμΉ: ${person.photo.location}</p>`);
}
function listRecentPhotos(outStream, photos) {
photos
.filter((p) => p.date > recentDateCutoff())
.forEach((p) => {
outStream.write('<div>\n');
emitPhotoData(outStream, p);
outStream.write(`<p>μμΉ: ${p.location}</p>`);
outStream.write('</div>\n');
});
}
function emitPhotoData(outStream, photo) {
outStream.write(`<p>μ λͺ©: ${photo.title}</p>`);
outStream.write(`<p>λ μ§: ${photo.date.toString()}</p>`);
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
function renderPhoto(photo) {
outStream.write(`<img src="${photo.src}" alt="${photo.alt}" />`);
}
function recentDateCutoff() {
return new Date('2022-11-20');
}
const rawPersonData = {
name: 'λ§ν΄ νμΈλ¬',
photo: {
src: 'https://commons.wikimedia.org/wiki/File:Webysther_20150414193208_-_Martin_Fowler.jpg',
alt: 'Martin Fowler.jpg',
title: '리ν©ν°λ§ μ μ',
location: 'μκ΅',
date: new Date('2022-11-19'),
},
};
const photos = [
{
src: 'https://commons.wikimedia.org/wiki/File:Webysther_20150414193208_-_Martin_Fowler.jpg',
alt: 'Martin Fowler.jpg',
title: '리ν©ν°λ§ μ μ',
location: 'μκ΅',
date: new Date('2022-11-19'),
},
{
src: 'https://github.com/read-with-us/refactoring/blob/main/images/cover.jpg',
alt: '리ν©ν°λ§ νμ§',
title: '리ν©ν°λ§ μ±
',
location: 'νκ΅',
date: new Date('2022-11-26'),
},
];
const outStream = {
write: function (content) {
console.log(content);
},
};
renderPerson(outStream, rawPersonData);
listRecentPhotos(outStream, photos);