영어 알파벳의 처음 m자를 포함하는 길이가 m인 문자열이 있지만 어떻게든 문자열에서 한 요소가 누락되었습니다. 이제 문자열에 m-1 글자가 포함됩니다.
그러한 문자열을 받아서 문자열에서 누락된 요소를 반환하는 함수를 작성해야 합니다.
따라서 이 함수의 코드를 작성해 보겠습니다 -
예시
이에 대한 코드는 -
const str = "acdghfbekj";
const missingCharacter = str => {
// to make the function more consistent
const s = str.toLowerCase();
for(let i = 97; ; i++){
if(s.includes(String.fromCharCode(i))){
continue;
};
return String.fromCharCode(i);
};
return false;
};
console.log(missingCharacter(str)); 출력
콘솔의 출력은 -
i