[プログラマ]中間文字を入力


中間文字を入力



に答える

function solution(string) {
  if (string.length % 2 === 0) {
    const half = string.length / 2;
    return string[half - 1] + string[half];
  } else {
    const half = string.length / 2;
    return string[Math.floor(half)];
  }
}

console.log(solution("abcde"));
console.log(solution("qwer"));