Skip to content

Commit 665d0e8

Browse files
committed
solve ab_check challenge
1 parent 73cfcf8 commit 665d0e8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ab_check.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* AB Check *
6+
* Using the JavaScript language, have the function ABCheck(str) take the str *
7+
* parameter being passed and return the string true if the characters a and b are *
8+
* separated by exactly 3 places anywhere in the string at least once *
9+
* (ie. "lane borrowed" would result in true because there is exactly three characters *
10+
* between a and b). Otherwise return the string false. *
11+
* *
12+
* SOLUTION *
13+
* I am goint to use a RegExp to see if the patter [a...b] exists anywhere in the *
14+
* string. If it does then return true else return false. *
15+
* *
16+
* Steps for solution *
17+
* 1) Use RegExp pattern to search string for pattern a...b *
18+
* 2) If found return true *
19+
* 3) Else return false *
20+
* *
21+
***************************************************************************************/
22+
23+
function ABCheck(string) {
24+
const reg = string.search(/a...b/);
25+
return reg > -1 ? "true" : "false";
26+
}
27+
28+
console.log(ABCheck('asssba'))
29+
console.log(ABCheck('lane borrowed'))
30+
console.log(ABCheck('lane borrowed'))
31+
console.log(ABCheck('aasasasas'))
32+
console.log(ABCheck('aabb'))
33+
console.log(ABCheck('aabbccddeefghi'))
34+

0 commit comments

Comments
 (0)