I have a slight problem with this challenge. When I test it in my IDE I get perfectly fine results, but fcc doesn’t accept it all. Maybe you can have a look if I miss something or I just have a total wrong approach.
The linter does not like the fact that you did not explicitly use { and } to surround your for loop’s code block.
Actually, even once you fix that, your function will fail the 3rd and 4th tests. It will also fail those tests in your IDE as you currently have it written.
Like the others, I’d expect your solution to not work either, as your approach makes some assumptions that aren’t always going to be the case.
I just attempted that challenge myself and the way I did it was basically by taking advantage of ASCII codes, as it’s generally easier to work with numbers than characters. Of course you can use RegEx too, as mentioned, but that’s generally sort of a quick-fix approach and probably not the approach that FCC wants you to take since RegExs don’t involve “algorithmic scripting”.
This is my solution, there are plenty of others that would work too:
function fearNotLetter(str) {
let arr = str.split("");
let ascii = arr.map(x => x.charCodeAt(0));
for (let i = 1; i < ascii.length; i++) {
if (ascii[i] > ascii[i-1] + 1) {
return String.fromCharCode(ascii[i] - 1);
}
}
}
@astv99, @R-Todorov Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, please try to avoid posting full working solutions. Instead stick to giving suggestions and hints or examples similar, but not exact.