Know Your Neighbor // Edabit
I’m trying to solve this coding problem (). But I’m not able to. Is this a hard problem? Or am I just too bad? Pls, be honest.
I have been working on this for 3 hours! YES REALLY!!
Please help me out.
Here’s my solution:-
function plusSign(str) {
if (str[0]!="+" || str[str.length-1]!="+") {
console.log(false);
return false;
}
for (index in str) {
// console.log(index);
console.log(str[index-1])
console.log(index, str[index+1])
if (Number(str[index]) == NaN) {
console.log(str[index]);
if (str[index-1] && str[index+1]) {
if (str[index-1] == "+" && str[index+1] == "+") {
console.log("LOGGED STR", str);
}
}
}
}
}
plusSign("+f+d+c+#+f+");
plusSign("+d+=3=+s+");
plusSign("+d+k+##f+");
plusSign("a+")
plusSign("hf+d++#+f+")
// plusSign("+f+d+c+#+f+") ➞ true
// plusSign("+d+=3=+s+") ➞ true
// plusSign("f++d+g+8+") ➞ false
// plusSign("+s+7+fg+r+8+") ➞ false
What’s the problem with the code?
Thank you!