function fearNotLetter(str) {
let letters = /^[A-Za-z]+$/;
let i = "a";
for (i = 0; i < str.length; i += 1) {
if (str.length === letters) {
return undefined;
} else
return //missing letter;
}
};
console.log(fearNotLetter("abce"));
I am stuck, can someone help me out without giving me the answer?
function fearNotLetter(str) {
// Step 1: Indicate the alphabet range
// Step 2: If all letters in str are present then return undefined
// Step 3: If a letter in the str is not present then return the missing letter
// *Key: str must be in the correct order of the alphabet
fearNotLetter("abce");
I wrote out in plain english how I would solve this, I think the difficult part is writing code that takes the order of the letters in the str into consideration, which I wrote as the key to this problem
function fearNotLetter(str) {
// Step 1: Create a variable for the alphabet
// Step 2: Create a for loop that checks if all the letters in the str are in the same order as they are in the alphabet
// Step 3: If they are, return undefined
// Step 4: If not, return the missing letter
console.log(fearNotLetter("abce"));
I tried giving more detail in these steps. Other than these steps I wrote, I am unsure of any other way to approach this problem
Hey Zuko,
I went thru your description and code and basically you are right, you need to loop thru, you need to tell how to know the position in the alphabet and then compare. I dont think you can do that with a regex expression though. I mean, you would have to populate your own array where each letter of the alphabet represents an index and then compare with the length of the given argument.
But, why to invent the wheel a second time? Imagine that your pc has to tell which key was pushed, ofcourse this wouldnt be the same as we see, it would be hex to binary. So each letter/ character has already its very own number.
function fearNotLetter(str) {
const stringabc = "abcdefghijklmnopqrstuvwxyz";
for (let i = 0; i < stringabc.length; i += 1) {
if (str.charCodeAt() - stringabc.charCodeAt(str.charCodeAt()) != 0) {
return //missing letter;
}
return undefined;
}
};
console.log(fearNotLetter("abce"));
I feel like I am close but I don’t know what I am doing wrong. I thought my code uses a for loop to look through stringabc then uses an if statement that says if the value of the letters in the str aren’t equal to the value of the same letters in their position of the alphabet…then return the missing letter, otherwise return undefined