const runTests = (cb) => {
const testCases = [
["a","b","c","d","f"],
["O","Q","R","S"],
["F","H","I","J","K"],
["j","l"],
["i","j","k","l","m","n","o","q"],
["K","L","M","N","O","Q","R","S"],
["i","j","l","m","n","o","p","q"],
["A","B","D","E","F"],
["h","i","k","l","m"]
];
testCases.forEach((item)=>{
cb(item);
});
};
const findMissingLetter = (list) => {
let lastCode = list[0].charCodeAt(0);
for (let i = 1; i < list.length; i++){
const currentCode = list[i].charCodeAt(0);
if (currentCode > lastCode + 1) {
return String.fromCharCode(currentCode - 1);
}
lastCode = currentCode;
}
}
runTests(findMissingLetter);
const findMissingLetter = (arr) => {
arr = arr.sort(); // just in case
for (let i = 0; i < arr.length-1; i++) {
const nextChar = {
inAlphabet: String.fromCharCode(arr[i].charCodeAt(0) + 1),
inArray: arr[i+1]
}
if (nextChar.inAlphabet !== nextChar.inArray) {
return nextChar.inAlphabet
}
}
return 'No missing letters found'
}
runTests(findMissingLetter);
const findMissingLetter = (list) => {
const charCodes = list.map(i => i.charCodeAt(0));
const findCode = () => {
for (let i = 0; i < charCodes.length; i++) {
if (charCodes[i] - charCodes[i + 1] < -1) {
return charCodes[i] + 1;
}
}
}
return String.fromCharCode(findCode());
}
runTests(findMissingLetter);
const findMissingLetter = (list) => {
for (let i = 0; i < list.length; i++) {
if (list[i].charCodeAt(0) - list[i + 1].charCodeAt(0) < -1) {
return String.fromCharCode((list[i].charCodeAt(0) + 1))
}
}
};
runTests(findMissingLetter);
let encoder = new TextEncoder();
let decoder = new TextDecoder();
let result;
function findMissingLetter (arr) {
let textCodes = arr.map(function(item) {
return Number(encoder.encode(item));
});
for (let i = 0; i < textCodes.length; i++) {
if (textCodes[i + 1] - textCodes[i] > 1) {
result = decoder.decode(new Uint8Array([textCodes[i] + 1]));
return result;
}
}
}
runTests(findMissingLetter);
const findMissingLetter = (arr) => {
let letters = 'abcdefghijklmnopqrstuvwxyz';
if (arr[0] === arr[0].toUpperCase()) {
letters = letters.toUpperCase();
}
letters = letters.split('');
const firstLetterIndex = letters.indexOf(arr[0]);
for (let startIndx = firstLetterIndex, i = 0; startIndx < letters.length; i++, startIndx++) {
if (letters[startIndx] !== arr[i]) {
return letters[startIndx];
}
}
}
runTests(findMissingLetter);
const findMissingLetter = (arr) => {
for (let i = 0; i < arr.length-1; i++) {
const nextChar = {
inAlphabet: String.fromCharCode(arr[i].charCodeAt(0) + 1),
inArray: arr[i+1]
}
if (nextChar.inAlphabet !== nextChar.inArray) {
return nextChar.inAlphabet
}
}
return 'No missing letters found'
}
runTests(findMissingLetter);
const findMissingLetter = (list) => {
const nextLetters = {A:"B",B:"C",C:"D",D:"E",E:"F",F:"G",G:"H",H:"I",I:"J",J:"K",K:"L",L:"M",M:"N",N:"O",O:"P",P:"Q",Q:"R",R:"S",S:"T",T:"U",U:"V",V:"W",W:"X",X:"Y",Y:"Z",
a:"b",b:"c",c:"d",d:"e",e:"f",f:"g",g:"h",h:"i",i:"j",j:"k",k:"l",l:"m",m:"n",n:"o",o:"p",p:"q",q:"r",r:"s",s:"t",t:"u",u:"v",v:"w",w:"x",x:"y",y:"z"};
let lastLetter = list[0];
for (let i = 1; i < list.length; i++){
const currentLetter = list[i];
const correctLetter = nextLetters[lastLetter];
if (correctLetter !== currentLetter) {
return correctLetter;
}
lastLetter = currentLetter;
}
}
runTests(findMissingLetter);