Skip to content

re: Daily Challenge #60 - Find the Missing Letter VIEW POST


Here is another JS version

const LETTERS = [
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 
  'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
  'x', 'y', 'z'

const findMissing = ltrArr => {
  const offset = LETTERS.findIndex(l => l === ltrArr[0].toLowerCase());
  const index = ltrArr.findIndex((l, i) => l.toLowerCase() !== LETTERS[offset + i]);

  return ltrArr[0].toLowerCase() === ltrArr[0]
    ? LETTERS[index + offset]
    : LETTERS[index + offset].toUpperCase();

The LETTERS constant could be inside the findMissing function... but that seemed less reusable. Covers all the test cases and should only iterate the arrays fully if there is no missing character to be found. So should be pretty fast as well.

code of conduct - report abuse