728x90
#문제
영화 정보가 담긴 객체를 요소로 갖는 배열과 연도를 입력받아 해당 연도 이전의 영화를 요소로 갖는 배열을 리턴해야 합니다.
영화제목 by 영화감독 의 형태를 가져야한다.
#예시
let output = classicMovies(
[
{
title: 'Batman',
year: 1989,
director: 'Tim Burton',
imdbRating: 7.6,
},
{
title: 'Batman Returns',
year: 1992,
director: 'Tim Burton',
imdbRating: 7.0,
},
{
title: 'Batman Forever',
year: 1995,
director: 'Joel Schumacher',
imdbRating: 5.4,
},
],
1993
);
console.log(output); // --> ["Batman by Tim Burton", "Batman Returns by Tim Burton"]
#풀이
`${num.title} + by + ${num.director}` 이렇게 + 넣으면 안된다!
#정답
function classicMovies(arr, year) {
//배열안에 객체 집단있다
//filter로 year이전의 영화 걸러내고
//map으로 title+by+director 하면 되겟다
let oldlist = arr.filter(num => num.year < year);
return oldlist.map(num => `${num.title} by ${num.director}`);
}
728x90