Find the missing letter

JavaScript

function findMissingLetter(array) {
  let previousCharCode = '';
  for (let i = 0; i < array.length; i++) {
    const charCode = array[i].charCodeAt(0);
    if (previousCharCode != '' && charCode != previousCharCode + 1) {
      return String.fromCharCode(charCode - 1);
    } else {
      previousCharCode = charCode;
    }
  }

  return ' ';
}

Tags

  1. javascript (Private)
  2. 6-kyu (Private)
  3. codewars (Private)
  4. answer (Private)