Like this:
if (str.indexOf("Yes") >= 0)
...or you can use the tilde operator:
if (~str.indexOf("Yes"))
This works because indexOf() returns -1 if the string wasn't found at all.
Note that this is case-sensitive.
If you want a case-insensitive search, you can write
if (str.toLowerCase().indexOf("yes") >= 0)
Or:
if (/yes/i.test(str))
function mutation(arr) {
let first = arr[0];
let second = arr[1];
return first.indexOf(second) !== -1;
}
console.log(mutation(["hello", "hel"]));
#is target in base?
def findSubstring(base, target):
match = ""
for x in range(0, len(base)):
substring = base[0:len(base)-x]
if substring == target:
print("there is a match")
match = substring
if match == "":
return ""
else:
return match
print(findSubstring("aaaaaaa", "aaa"))