Created
August 9, 2012 06:32
-
-
Save anonymous/3301694 to your computer and use it in GitHub Desktop.
coderbyte "Simple Symbols"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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