Skip to content

Commit eb69446

Browse files
committed
Create Simple Symbols
1 parent 7c571ed commit eb69446

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Simple Symbols

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* Simple Symbols *
6+
* Using the JavaScript language, have the function SimpleSymbols(str) take the str *
7+
* parameter being passed and determine if it is an acceptable sequence by either *
8+
* returning the string true or false. The str parameter will be composed of + and = *
9+
* symbols with several letters between them (ie. ++d+===+c++==a) and for the string *
10+
* to be true each letter must be surrounded by a + symbol. So the string to the left *
11+
* would be false. The string will not be empty and will have at least one letter. * *
12+
* *
13+
* SOLUTION *
14+
* When reading the directions for this challenge you have to be aware of the adage *
15+
* "Attention to detail, all the time!" The instructions immediately tell you that *
16+
* you will have two outliers that you have to account for in your solution. They are *
17+
* the first and last characters. If these are letters then you have to return false *
18+
* because there cannot be a + before or after these letters.
19+
* *
20+
* Steps for solution *
21+
* 1) Convert string to an Array. *
22+
* 2) Loop thru each letter in array *
23+
* 3) If first character or last character is letter a-z then return false (outlier)*
24+
* 4) If charcter is string then check if letter before and after is + and if not *
25+
* then return false *
26+
* 5) If looped through whole array and everything matches then return true *
27+
* *
28+
***************************************************************************************/
29+
30+
function SimpleSymbols(str) {
31+
32+
var arr = str.toLowerCase().split("");
33+
for (var i = 0; i < arr.length; i++) {
34+
if (arr[i] >= "a" && arr[i] <= "z") {
35+
if (i === 0 || i === arr.length) {
36+
return false;
37+
}
38+
39+
if (arr[i-1] !== "+" || arr[i+1] !== "+") {
40+
return false;
41+
}
42+
}
43+
}
44+
45+
return true;
46+
47+
}

0 commit comments

Comments
 (0)