# Help solving Mutations w/o indexOf()

Help solving Mutations w/o indexOf()
0

#1

I’m aware that solutions use indexOf() and I will get started solving it that way but I started solving it with like this and I just want to finish it lol.

``````function mutation(arr) {
var firstArr=arr[0].toLowerCase().split("");
var secondArr=arr[1].toLowerCase().split("");
var k=[];
for(var i=0;i<firstArr.length;i++){
for(var j=0;j<secondArr.length;j++){
if (firstArr[i]==secondArr[j]){
k++;
}
}}
return k==secondArr.length;
}
``````

I have gotten most of the cases correct except that my counter K doesn’t take into account if the same letter is counted more than once like the “l” in hello. I want to know if there is even anything I can do to fix that. I tried figuring it out but I need some help. Thanks!

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

I am curious to know what your algorithm is you are basing your current code on?

Make sure you have your algorithm (steps/logic) ironed out before trying to code. If I were to read your algorithm written in normal language or pseudo-code, I should still be able to get the same answer. Then, you can translate your logic to code. You can still use two for loops, but it will look much different than your current approach.

Sometimes, we have to start over when are approach either does not solve the task or gets overly complicated. In this situation, it is simply that your code logic will not work. Trying to “patch” it up will make it overly complicated.

If you get stuck on the written algorithm, post what you have and we can take a look to see if you are heading in the right direction. In the end, you DO NOT have to use indexOf to solve this challenge.