Skip to content

Instantly share code, notes, and snippets.

Created August 9, 2012 06:32
Show Gist options
  • Save anonymous/3301694 to your computer and use it in GitHub Desktop.
Save anonymous/3301694 to your computer and use it in GitHub Desktop.
coderbyte "Simple Symbols"
/* Have the function SimpleSymbols(str) take the str parameter being passed
and determine if it is an acceptable sequence by either returning true or false.
The str parameter will be composed of + and = symbols with several letters between them (ie. ++d+===+c++==a)
and for the string to be true each letter must be surrounded by a + symbol.
*/
function SimpleSymbols(str) {
var result;
var letterCounter = 0;
var successCounter = 0;
var letters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var chars = str.split('');
for (var k in chars) {
if (letters.indexOf(chars[k]) !== -1) {
letterCounter += 1;
if (chars[k - 1] === '+' && chars[k + 1] === '+') successCounter += 1;
}
}
if (letterCounter === successCounter) { return console.log(true); }
else { console.log(false); }
}
SimpleSymbols('+d+=3=+s+');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment