강의

멘토링

커뮤니티

Inflearn Community Q&A

frontendended's profile image
frontendended

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

15. Output middle character (substring, substr)

가운데 문자 출력 이렇게 풀어도 될까요?

Written on

·

253

·

Edited

0

function solution (str)

{

    let strArr = str.split("");

    let length = strArr.length;

    let answer = '';

    answer =  length/2 !== Math.round(length/2) ? strArr[Math.round(length/2)-1] : strArr[length/2 -1] + strArr[length/2];


    return answer;

}  
console.log(solution("good"));

javascript코딩-테스트

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

삼항연산자를 이용해서 길이가 짝수인지 홀수인지 판단하는 좋은 코드네요. 잘 하신 좋은 코드입니다. 잘 하셨습니다.

frontendended's profile image
frontendended

asked

Ask a question