GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledge of TypeScript.
Hands-on real world projects that will help you exercise your knowledge of TypeScript. - GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledg...
github.com
정말 잘하고 있어요, 친구.
다음 멋진 디너 파티에 당신을 초대하고 싶어요.
그러고 보니 초대장과 좌석 배정을 무작위로 지정하려면 프로그램을 제대로 입력해야 합니다.
내 친구들은 좀 유치할 수 있습니다. 아이들처럼 자리에 엄청 고집을 부립니다.
지난 단계에서 문자열 리터럴 유니온 타입으로 수행했던 작업이 마음에 듭니다.
이 항목에서도 문자 타입을 사용하지 말고 리터럴 타입을 사용해주세요.
아, 여기도 이름 중 하나에 오타가 있는 것 같아요.
# 파일
index.ts: 여기에서 타입 어노테이션 수정
solution.ts: 솔루션 코드
const headOfTable = "Me!";
let adjacentLeft: "Susie" | "Tommy";
let adjacentRight: "Susie" | "Tommy";
let furtherLeft: "Angelica" | "Chuckie" | undefined;
let furtherRight: "Chuckie" | "Kimi" | "Timmy" | undefined;
// I always invite Susie and Tommy! ♥
if (Math.random() > 0.5) {
adjacentLeft = "Susie";
adjacentRight = "Tommy";
} else {
adjacentLeft = "Tommy";
adjacentRight = "Susie";
}
// I invite Angelica about half of the time. We're not as close as Susie and Tommy. It's a long story.
// I try to fill `furtherLeft` first...
if (Math.random() > 0.5) {
furtherLeft = "Angelica";
}
// Same with Chuckie. I like them, but do I *really* like hanging out with them? Only sometimes.
// ...then after that `furtherRight`
if (Math.random() > 0.5) {
if (furtherLeft) {
furtherRight = "Chuckie";
} else {
furtherLeft = "Chuckie";
}
}
// If I invited Angelica but not Chuckie, I'll invite Kimi. They get along well with Angelica but not Chuckie.
if (furtherLeft === "Angelica" && furtherRight !== "Chuckie") {
furtherRight = "Kimi";
}
// If I invited Chuckie but not Angelica, I'll invite Timmy. They get along well with Chuckie but not Angelica.
if (furtherLeft === "Chuckie") {
furtherRight = "Timmy";
}
console.log(`At the head of the table is... ${headOfTable}`);
console.log(`Adjacent to the left is: ${adjacentLeft}`);
console.log(`Adjacent to the right is: ${adjacentRight}`);
console.log(`Further down on the left is: ${furtherLeft ?? "nobody"}`);
console.log(`Further down on the right is: ${furtherRight ?? "nobody"}`);
export {};
이전 문제와 동일하다
728x90
'Typescript > 러닝 타입스크립트 연습문제' 카테고리의 다른 글
(4장) Various Lawyerings - 1.Aviary Classification (0) | 2023.04.12 |
---|---|
(3장 심화) The Narrow Trail (0) | 2023.04.06 |
(3장) Primitive Cooking - 2. Recipes (0) | 2023.04.06 |
(3장) Primitive Cooking - 1. Ingredients (0) | 2023.04.06 |
(2장) System of a Clown - 2. Clown Availability (0) | 2023.04.06 |