Skip to content

Commit 9358187

Browse files
authored
Update AB Check
1 parent 73cfcf8 commit 9358187

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

AB Check

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919
* 3) Else return false *
2020
* *
2121
***************************************************************************************/
22-
function ABCheck(str) {
23-
24-
var match = str.search(/a...b/);
25-
if (match > -1) {
26-
return "true";
22+
function ABCheck(str) {
23+
for (let i = 0; i < str.length - 4; i++) {
24+
if ((str[i] === 'a' && str[i + 4] === 'b') || (str[i] === 'b' && str[i + 4] === 'a')) {
25+
return true;
26+
}
2727
}
28-
else {
29-
return "false";
30-
}
31-
28+
return false;
3229
}

0 commit comments

Comments
 (0)