문제
N개의 문자열이 입력되면 그 중 가장 긴 문자열을 출력
풀이 과정 a
const solutionA = (wordArray) => {
const answer = {
word: wordArray[0],
length: wordArray[0].length,
};
for (let i = 1; i < wordArray.length; i++) {
const currentWord = wordArray[i];
if (currentWord.length > answer.length) {
answer.word = currentWord;
answer.length = currentWord.length;
}
}
return answer.word;
};
const testA = solutionA(['teacher', 'time', 'student', 'beautiful', 'good']);
console.log(testA);
틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄