Skip to content

Instantly share code, notes, and snippets.

@ikyamelia
Created August 12, 2021 04:38
Show Gist options
  • Save ikyamelia/bdef354157e46d52ffc47d5af0c2dc73 to your computer and use it in GitHub Desktop.
Save ikyamelia/bdef354157e46d52ffc47d5af0c2dc73 to your computer and use it in GitHub Desktop.
Tech Tryout Glints-03
function ABCheck(str) {
var arr = str.toLowerCase().split("").join("").replace( /\s/g, "")
for(var i = 0; i < arr.length; i++) {
if(arr[i].indexOf('a') != -1 && arr[i+3].indexOf('b') != -1) {
return true
}
}
return str;
}
// keep this function call here
console.log(ABCheck(readline()));

AB Check

Have the function ABCheck(str) take the str parameter being passed and return the string true if the characters a and b are separated by exactly 3 places anywhere in the string at least once (ie. "lane borrowed" would result in true because there is exactly three characters between a and b). Otherwise return the string false.

Examples

Input: "after badly" Output: false

Input: "Laura sobs" Output: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment