-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path11-ABCheck.js
More file actions
20 lines (19 loc) · 955 Bytes
/
11-ABCheck.js
File metadata and controls
20 lines (19 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// STEPS:
// 1. Convert the user-inputted string to all lowercase. Then split it based on character ('').
// 2. Create a FOR-Loop to run thru the characters. FOR EACH character...
// - IF (the current character is an 'a') AND either (the character 4 elements previous is a 'b') OR (the character 4 elements after is a 'b')...
// -> Return true
// - IF (the current character is an 'b') AND either (the character 4 elements previous is an 'a') OR (the character 4 elements after is an 'a')...
// -> Return true
// 3. Otherwise, return false
function ABCheck(str) {
var components = str.toLowerCase().split('');
for (i = 0; i < components.length; i++) {
if ((components[i] === 'a') && ((components[i - 4] === 'b') || (components[i + 4] === 'b'))) {
return true;
} else if ((components[i] === 'b') && ((components[i - 4] === 'a') || (components[i + 4] === 'a'))) {
return true;
}
}
return false;
}