Hi,
New to posting so sorry if this is in the wrong place!
I am looking for help, my code so far for the missing letters challenge doesnt work and I cant work out why.
I have it returning the missing letter in a string of letters when it passes a test in a map function but also returning ‘undefined’ when my test for the missing letter isnt passed, I dont know how to stop this?
(I know there are easier ways to do this having looked at the hints but would appreciate understanding why my way doesnt work)
Your code so far
function fearNotLetter(str) {
let fear = {
'a':1,
'b':2,
'c':3,
'd':4,
'e':5,
'f':6,
'g':7,
'h':8,
'i':9,
'j':10,
'k':11,
'l':12,
'm':13,
'n':14,
'o':15,
'p':16,
'q':17,
'r':18,
's':19,
't':20,
'u':21,
'v':22,
'w':23,
'x':24,
'y':25,
'z':26}
let str1=str.split("");
return str1.map(function(val,index,array){
if((fear[val])!== (fear[array[index+1]]-1) && (str1.length-1>index))
{return String.fromCharCode(val.charCodeAt()+1)}
else return;
});
}
console.log(fearNotLetter("abce"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Missing letters
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters