Tell us what’s happening:
i think my code is okay like this
but my tests 3 ,7,10 and 11 are not passing
is there a way out for this?
Your code so far
const mutation = (arr) => {
let str1 = arr[0].toLowerCase()
let str2 = arr[1].toLowerCase()
for(const char of arr){
if(str1.includes(char) === str2.includes(char)){
return true
}
else if(str1.includes(char) !== str2.includes(char)){
return false
}
}
}
console.log(mutation(["hello", "hey"]))
mutation(["hello", "hey"])
mutation(["hello", "Hello"])
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])
mutation(["Mary", "Army"])
mutation(["Mary", "Aarmy"])
mutation(["Alien", "line"])
mutation(["hello", "neo"])
mutation(["voodoo", "no"])
mutation(["ate", "date"])
mutation(["Tiger", "Zebra"])
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Implement the Mutations Algorithm - Implement the Mutations Algorithm
Hi there!
Please log char
inside your for
loop, so you can see what you are working with.
Happy coding!
i have logged char
in but it is displaying nothing
Please share your updated code.
What are those tests (not just a number)? What debugging have you tried?
Let’s try it a different way. Please log "abc".includes("bac")
. What is the result? Is that what you expect the result to be?
1 Like
const mutation = (arr) => {
let str1 = arr[0].toLowerCase()
let str2 = arr[1].toLowerCase()
for(const char of arr){
if(str1.includes(char) === str2.includes(char)){
console.log(char)
return true
}
else{
return false
}
}
}
mutation(["hello", "hey"])
I tried this
and I get false
which is what I expected
let check = "abc".includes("bac")
console.log(check)
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])
mutation(["ate", "date"]
mutation(["Tiger", "Zebra"])
mutation(["floor", "for"])
ILM
June 24, 2025, 8:41am
10
move the console.log inside the loop, outside the if statement
Why do you expect false? All the letters in the first string are also in the second, so this should return true but does not. Re-read the instructions again.
mutation
should return true
if the string in the first element of the array contains all of the letters of the string in the second element of the array
You didn’t really answer what I asked. It’s actually important to me able to talk about what is not working and what you’ve tried to fix it.
actually,it should return true
but ,why is it returning false ?
or is it neccessary the first character in the first string must be the same as that of the second string?
I tried using the for loop
but all the arrays that should return true passed, why those that is expected to return false didn’t.
I would be glad If you can help me out of this
How is the for
loop a debugging step? I don’t understand.
What does a return
statement do? Can the function continue running after hitting a return
statement?
The order of the letters is unimportant. Try to think of a way you can determine if every letter in str2
is included in str1
.