need guidance if this code is good enough for an answer on an interview question? [closed]

the challenge: Have the function SimpleSymbols(str) take the str parameter being passed and determine if it is an acceptable sequence by either returning the string true or false. The str parameter will be composed of + and = symbols with several characters between them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the left would be false. The string will not be empty and will have at least one letter.

My solution and pseudo code:
// if(str[i] === letter) check if its a + at str[i – 1] || str[i + 1]

let a = "abcdefghijklmnopqrstuvwxyz"
let letters = a.split('')
for(let i = 0; i < str.length; i++){

if(letters.includes(str[i])){// if str[i] == d
for(let j = i; j < str.length; j++){//start a for loop that starts at d and ends at the index behind d
if(str[j + 1] === "+"){
for(let k = str.length - 1; k > 0; k--){
if(str[i - 1] === "+"){
return true
} else{
return false
}
}
}
//if(i[j] === "+"){//if the index is str[i] == +
//   for(let k = str[i]; k >= str[i + 1]; k++){//start another loop that starts at str[i] and moves forward twice
//     if(str[i + 1] === "+"){
//       return true
//     } else{
//       return false
//     }
//   }
// }
}
}
}

}

I needed to console.log a lot to see exactly where i was. originally i tried to execute a loop at the exact location of a letter. from there i only wanted to move backwards once and identify if “+” was there. If that was true i wanted to move forward twice from that exact location and check if there was another “+”. It identified a letter, checked for a “+” behind the letter, moved passed the letter to check for another “+”. I didnt understand how to implement that so i figured how to just loop through the entire length at the same position and once it found the “+” both ways we recieved the desired outcome.

Input: “+d+=3=+s+”
Output: true

Input: “f++d+”
Output: false

would this be considered easy code to read. I ask chatGPT and to me it was wayyy more complex then my code.

  • 1

    Welcome to Stack Overflow! If this is otherwise working code, you may be looking for Code Review instead. Please see A guide to Code Review for Stack Overflow users as these communities have different standards and guidelines and your question may need some changes when posting there. To learn more about this community and how we can help you, please start with the tour and read How to Ask and its linked resources.

    – 

  • Tangential (post is off-topic), but not if it’s indented like that, no. Also j + 1 given the for loop termination expr seems fishy, using let for the unmodified ref, also what is k for since it’s not used anywhere, and formatting questions matters as much as formatting code.

    – 




Leave a Comment