Intermediate Algorithm Scripting - Missing letters

Tell us what’s happening:
If you want the code to return all the missing char, you can take a look at my solution.
My code does not use regex so it is easier to understand and it returns all the missing word.

Your code so far

function fearNotLetter(str) {
  let thing = [];
  let thin = str.split('')
                .map(i=>i.charCodeAt());
  for (let i=thin[0];i<thin[thin.length-1];i++){
    if(thin.some(digit=>digit==i)){} 
    else thing.push(i);
  }
  return thing == 0
        ?undefined
        :String.fromCharCode(...thing);
};
console.log(fearNotLetter("ahz"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Missing letters

Link to the challenge:

The solutions are fine. Only one letter is expected to be returned.

The problem doesn’t say what should happen if multiple letters are missing.

Your solution doesn’t handle the case when two letters are transposed, which is also not covered by the challenge.

I think both questions are interesting ‘bonus’ challenges once you pass the tests for the challenge.

3 Likes

Thank you for your advice, I just wanna contribute to the community,.
I just think that we should return all the missing letters.
About the transpose, just use sort and that solves the problem.
update my code:

function fearNotLetter(str) {
  let thing = [];
  let thin = str.split('')
                .map(i=>i.charCodeAt())
                .sort((a,b)=>a-b);
  for (let i=thin[0];i<thin[thin.length-1];i++){
    if(thin.some(digit=>digit==i)){} 
    else thing.push(i);
  }
  return thing == 0
        ?undefined
        :String.fromCharCode(...thing);
};
console.log(fearNotLetter("haz"));

But that’s not what the instructions are asking. They are asking to return the one missing letter (or undefined if none or missing). So critcizing the current solutions for doing exactly what they are being asked to do is not valid.

2 Likes

Like I said, it’s an interesting question, but its more than what is being asked for here

Sort doesn’t solve the problem of your code not detecting when letters are transposed.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Sorry, my bad.
I am gonna edit my post.

Thank you for doing it for me, next time I will do like that.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.