DEV Community

loading...

Discussion on: Daily Challenge #60 - Find the Missing Letter

Collapse
marcoslooten profile image
Marco Slooten

Nice challenge, I tried doing it in JS with an array.reduce and character codes. I think it works well enough! I don't think the arr.splice(1) is really clean though, so perhaps a traditional loop would be better.

const returnMissingLetter = letters => {
  return letters.reduce((acc, curr, i, arr) => {
    if (curr.charCodeAt() - acc.charCodeAt() === 1) {
      return curr;
    }
    arr.splice(1);
    return String.fromCharCode(acc.charCodeAt() + 1);
  });
};