let books = [
{ id: 1, title: "War and Peace", author: "Leo Tolstoy" },
{ id: 2, title: "The Old Man and the Sea", author: "Ernest Hemingway" },
{ id: 3, title: "The Republic", author: "Plato" },
{ id: 4, title: "Meditations", author: "Marcus Aurelius" },
{ id: 5, title: "Anna Karenina", author: "Leo Tolstoy" },
{ id: 6, title: "A Farewell to Arms", author: "Ernest Hemingway" },
];
function checkAuthor(input) {
for(var i = 0 ; i < books.length; i++) {
return books[i].author === input;
};
}
checkAuthor("Plato")
이거 왜 자꾸 false라고 나오는 건가여??
id3에 Plato가 있으니까 배열 순차적으로 돌면서 확인하고
true로 나와야하는 거아닌가요?
틀린 경우도 return하니까 루프가 종료됨
true 값으로 받고 싶다면 어떻게 코드를 짜야할까요? ㅜㅜ
바보냐?
아 정말 고맙습니다!!!