-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimple_symbols.js
30 lines (21 loc) · 1.2 KB
/
simple_symbols.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
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. So the string to the left would be false. The string will not be empty and will have at least one letter. Use the Parameter Testing feature in the box below to test your code with different arguments. Do not modify the function name within the code. Do not put any code outside of the function and use the return keyword to return your answer from within the function.
*/
function SimpleSymbols(str) {
var LETTERS = 'abcdefghijklmnopqrstuvwxyz';
for (var i = 0; i < str.length; i++) {
if (LETTERS.indexOf(str.charAt(i)) != -1) {
if (i > 0 && i < (str.length - 1)) {
if (str.charAt(i - 1) != '+' || str.charAt(i + 1) != '+') {
return false;
}
} else {
return false;
}
}
}
return true;
}
// this call is needed to test your function
// keep this when you submit your code
SimpleSymbols(str)