To check if the second string is contained inside the first one I used the variable “match” to count how many letter match and if the number of matching letter were equal to the second string it would return true and if not, return false
function mutation(arr) {
let fstStr = arr[0].toLowerCase();
let sndStr = arr[1].toLowerCase();
for (let char of sndStr) {
if (fstStr.includes(char)) {
return true
} else {
return false
}
}
}
console.log(mutation([“hello”, “hey”]));
still I dont understand why the includes() finds “y” inside “hello”
the “for” loop was checking every letter of the string but having the condition for true or false being checked inside the “for” loop caused it to be true as soon as the first letter matched so I took the “if” out of the loop and the function worked
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
You should move “return true” outside of “if” statement. because this loop stopped immediately after match tow letters.
I used “continue” instead of return and it worked.