Trying to improve my javascript code in this simple challenge from coderbyte
Your version is actually not that bad but could be simplified slightly and wrapped in a function. You could use charAt to get the character from a string instead of splitting the string. You don't need the initial check on the first and last characters; you can just do these as part of the main loop. (This works because str.charAt(-1) and str.charAt(str.length) both just return empty strings. Similarly if you were using an array, arr[-1] returns undefined.)

Wrapping this in a function and returning false when a non-matching character is found makes the code more efficient, as it does not have to run through the remaining loops when it already knows the answer (this would be the same as inserting break into your code.)

The below code also checks that the characters are either +, =, or a letter, which your original code does not do (so it would accept "===+!+==+3+", for example).

var str = "++d+===+c++=a";
console.log(checkString(str));

function checkString(str) {
    for (var i = 0; i &lt; str.length; i++) {
        if (str.charAt(i) != '+' &amp;&amp; str.charAt(i) != '=' &amp;&amp; 
            !(str.charAt(i) &gt;= 'a' &amp;&amp; str.charAt(i) &lt;= 'z' &amp;&amp; 
              str.charAt(i - 1) == '+' &amp;&amp; str.charAt(i + 1) == '+')) {
            return false;
        }
    }
    return true;
}


To use regular expressions you need to write pattern.test(str), e.g. /[a-z]/gi.test('a') returns true. However the point of using regex is that you can test a whole string in one go, rather than character-by-character. I think the following will work:

/^((\+[a-z])*\+|=)+$/gi.test('++d+===+c++=a')