Here’s is my working code!
@ilenia 's suggestion seems to have fixed my code.
Here’s my final code (it was accepted as an answer by edabit)
I’m using @snowmonkey 's regex to get know if a letter is an alphabet.
function plusSign(string) {
if (string[0]!="+" || string[string.length-1]!="+") {
return false;
}
i = 1;
for (index in string) {
console.log(index, string[Number(index)-1]);
console.log(index, string[Number(index)]);
console.log(index, string[Number(index)+1]);
if (string[index].match(/[a-z]/i)) {
if (string[index-1] && string[Number(index)+1]) {
if (string[index-1]=="+" && string[Number(index)+1] == "+") {
continue;
}
else {
return false;
}
}
}
}
return true;
}
plusSign("+d+k+##f+");
plusSign("hf+d++#+f+")
plusSign("+abcdef+");
Thanks a lot, it works now! I feel very good, even though it took, a day and spoon-feeding of what I needed to do.
I like the approach of not just giving the working solution!