Basic Algorithm Scripting - Mutations

Just not sure whats wrong here
Your code so far

function mutation(arr) {
  let source = arr[0].toLowerCase();
  let mutant = arr[1].toLowerCase();
  let sourceArr = arr[0].split(" ")
  let mutantArr = arr[1].split(" ")
  let count = 0;

  for(let i = 0; i < mutant.length; i += 1 ){
    let check = mutant[i];

    
    if(source.includes(check)){
      count= count + 1
    }
  }

  if(count === mutant.length){
    return true

  }
  
  return false;
}

mutation(["hello", "hey"]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Mutations

Link to the challenge:

I’m not immediately sure either. Have you tried console logging intermediate results?

it works for all things false

Have you tried logging out intermediate variables? Do the arrays hold what you expect?

yea each variable is as desired… i havent confirmed the functionality of the syntax for to lower case in this context… im gonna look now

What’s in those arrays after you split? I’m suspicious

strings… hahaha containing the full word
it never split like i intended… why?

but the rest of the code still seems to work with it

I don’t think it worksas you intend if it not an array of letters

check still is “h” then “e” then “y”

unless its because .includes() works differently

Oh, you aren’t using those arrays. I’d delete them.

1 Like

why isnt any of them returning true ??

:no_mouth: :melting_face:

What’s count for one of those tests?

for hey the count is 2 …

console.log(mutation([“ate”, “date”]))
//count 0 1 2 3 false

What about a case that is supposed to be true?

i actually resolved it… thanks forthe guidance and the making me not feel alone. helps a lot

1 Like

can i show it here to you?
do you not really need to see it?
haha
would you wanna see what it ended up being?

Go for it. I’m curious