DEV Community

loading...

Discussion on: Daily Challenge #124 - Middle Me

Collapse
ramongebben profile image
Ramon Gebben

In JavaScript

const middleMe = (x, y, n) => {
  if (n % 2 !== 0) return x;
  const centerIndex = (n / 2);
  const arr = Array(n).fill(y);

  arr[centerIndex] = x;

  return arr.join('');
}