가장 긴 문자열 출력

jinny·2021년 8월 24일

Algorithm

목록 보기
10/34
post-thumbnail

가장 긴 문자열을 출력

function solution(str){

    let result, num = Number.MIN_SAFE_INTEGER;
    for(let x of str) {
       if(num<x.length) {
           num = x.length;
           result = x;
       }
    }
    return result;

  
}

let str = ['teacher', 'time', 'student', 'beautiful', 'good'] ;
console.log(solution(str));  // beautiful
profile
주니어 개발자의 기록

0개의 댓글