เรามีสตริงความยาว m ที่มีตัวอักษร m ตัวแรกของตัวอักษรภาษาอังกฤษ แต่อย่างใด องค์ประกอบหนึ่งหายไปจากสตริง ตอนนี้สตริงประกอบด้วย
m-1 letters
เราจำเป็นต้องเขียนฟังก์ชันที่รับสตริงดังกล่าวและส่งกลับองค์ประกอบที่ขาดหายไปจากสตริง
ตัวอย่าง
ต่อไปนี้เป็นรหัส -
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