๐Ÿ’™ Type Challenges/Typescript Exercises

[TS] TypeScript Exercises 1 ํ•ด์„ ๋ฐ ํ’€์ด

์„ ๋‹ฌ 2023. 7. 3. 14:52
๋ฐ˜์‘ํ˜•

Introduce

    We are starting a small community of users. For performance
    reasons we have decided to store all users right in the code.
    This way we can provide our developers with more
    user-interaction opportunities. With user-related data, at least.
    All the GDPR-related issues will be solved some other day.
    This would be the basis for our future experiments during
    these exercises.

 

์šฐ๋ฆฌ๋Š” ์ด์ œ ์œ ์ €๋“ค์„ ์œ„ํ•œ ์ž‘์€ ์ปค๋ฎค๋‹ˆํ‹ฐ ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•  ์—์ •์ž…๋‹ˆ๋‹ค. ์„ฑ๋Šฅ์ ์ธ ์ด์œ ๋กœ ์šฐ๋ฆฌ๋Š” ๋ชจ๋“  ์œ ์ €๋“ค์„ ์ฝ”๋“œ ๋‚ด์— ์ €์žฅํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ์šฐ๋ฆฌ๋Š” ๊ฐœ๋ฐœ์ž๋“ค์—๊ฒŒ ๋” ์œ ์ €์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๋ฅผ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ตœ์†Œํ•œ ์œ ์ €์™€ ๊ด€๋ จ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  GDPR๊ณผ ๊ด€๋ จ๋œ ์ด์Šˆ๋“ค์„ ์–ธ์  ๊ฐ€ ํ•ด๊ฒฐ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ์—ฐ์Šต๊ธฐ๊ฐ„๋™์•ˆ ์šฐ๋ฆฌ์˜ ๋ฏธ๋ž˜ ์‹คํ—˜์˜ ๊ธฐ๋ฐ˜์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

Exercise

Given the data, define the interface "User" and use it accordingly.

 

์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ์—์„œ User ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ •์˜ํ•˜๊ณ  ์‚ฌ์šฉํ•ด๋ณด์„ธ์š”

 

Code

export type User = {name: string, age: number, occupation: string};

export const users: User[] = [
    {
        name: 'Max Mustermann',
        age: 25,
        occupation: 'Chimney sweep'
    },
    {
        name: 'Kate Müller',
        age: 23,
        occupation: 'Astronaut'
    }
];

export function logPerson(user: User) {
    console.log(` - ${user.name}, ${user.age}`);
}

console.log('Users:');
users.forEach(logPerson);

 

https://typescript-exercises.github.io/#exercise=1&file=%2Findex.ts

 

TypeScript Exercises

A set of interactive TypeScript exercises

typescript-exercises.github.io

 

๋ฐ˜์‘ํ˜•