문제
소문자로 된 문자열이 입력되면 그 단어의 가운데 문자를 출력
단, 단어의 길이가 짝수일 경우 가운데 2개의 문자를 출력
풀이 과정 a
const solutionA = (numberArray) => {
return Math.min(...numberArray);
};
const testA = solutionA([5, 3, 7, 11, 2, 15, 17]);
console.log(testA);
풀이 과정 b
const solutionA = (word) => {
const answer = {
word,
isEven: word.length % 2 === 0,
};
const quotient = Math.floor(answer.word.length / 2);
return answer.isEven
? answer.word.slice(quotient - 1, quotient + 1)
: answer.word.slice(quotient, quotient + 1);
};
const testA = solutionA('study');
console.log(testA);
const testB = solutionA('good');
console.log(testB);
틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄