## Task 1 ![](https://i112.fastpic.ru/big/2020/0820/04/dfdb5b927e1be1dcc69577334dae6104.png) ```ts type Movie = { name: string, actors: Array<ActorId> }; type Actor = { name: string }; type Rating = { value: number }; declare function getMovie(id: MovieId): Promise<Movie>; declare function getActor(id: ActorId): Promise<Actor>; declare function getMovieRating(id: MovieId): Promise<Rating>; type MovieData = { movieName: string, actorNames: Array<string>, rating: number }; async function getData(id: MovieId): Promise<MovieData> { const movie = await getMovie(id); const movieRating = await getMovieRating(id); const actors = []; for (actorId of movie.actors) { const actorName = await getActor(actorId); actors.push(actorName) } return { movieName: movie.name, actorNames: actors, rating: movieRating } } ``` ## Task 2 ```ts type Props = { list: Array<string>, onItemClick: string => void }; class List extends Component<Props> { onClickHandler = item => () => { this.props.onItemClick(item) } render() { const { list, onItemClick } = this.props; return ( <ul> {list.map(item => ( <li key={item} onClick={this.onClickHandler(item)}>{item}</li> ))} </ul> ) // ... } } ``` ## Task 3 ```ts type State = { checkedItem: null | string; } class Alphabet extends PureComponent<{}, State> { constructor(props) { super(props); this.state = { checkedItem: null }; } static list = ['a', 'b', 'c']; setCheckedItem = (item: string) => { this.setState({ checkedItem: item }); } render() { return ( <List list={list} onItemClick={ this.setCheckedItem } /> ); } } ``` ## Task 4 ```ts const symbolDict = { '(': ')', '{': '}', '[': ']' }; function validate(str: string): boolean { const stack = []; const symbolArray = str.split(''); for (let i = 0; i < symbolArray.length; i++) { if (symbolDict.hasOwnProperty(symbolArray[i])) { stack.push(symbolDict[symbolArray[i]]); } else if (symbolArray[i] !== stack.pop()) { return false; } } return stack.length === 0; } validate('[ ]'); // -> true validate('('); // -> false validate('( ) [ ]'); // -> true validate('( [) ]'); // -> false validate('{ { { ( ( [ ( ) ] ) ) } } }'); // -> true validate('( { { { ( ( [ ( ) ] ) ) } } }'); // -> false ```