Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 263 Bytes

File metadata and controls

12 lines (11 loc) · 263 Bytes
const getMiddle = (s) => {
  if (s.length % 2 === 0) {
    return s.substring(s.length / 2 - 1, s.length / 2 + 1);
  } else {
    return s.substring(s.length / 2, s.length / 2 + 1);
  }
};

console.log(getMiddle("abbc"));
console.log(getMiddle("abc"));