Mutations freeCodeCamp Help needed

Tell us what’s happening:

Your code so far

function mutation(arr) {
  var str = arr[1];
  var main = arr[0];
  var arr1 = [];
  arr1 = arr[0].split("");
  //return arr1;
  var arr2 = [];
  arr2 = arr[1].split("");
  var count1;
  var count2;
  for(i= 0 ; i<arr[1].length;i++){
    if((arr1[i] !== arr2[i])){
  for(i= arr[1].length; i >0;i--){
    if((arr1[i] !== arr2[i])){
  if(count1 > 0 || count2 > 0){
    return true;
  }else {
    return false;

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0.

Link to the challenge:

What improvements do i have to make ??

Can you explain to us the algorithm you figured out that you based your code on? You do not seem to have a grasp on the actual steps it would take to solve the challenge.

You should use the String.prototype.indexOf() function, it helps finding a char in a string.
And as said @RandellDawson, use comments to explain what the code is doing :slight_smile:

comparing every word of the two words

That is not an algorithm. Plus, you don’t care if arr[0] has characters that are not in arr[1]. You only need to make sure the all the characters in arr[1] are present in arr[0]. For example, the following should result in true.

mutation(["abcdefghijklmnopqrstuvwxyz", "k"]);  // true because all the characters in the second element (i.e. "k") are present in "abcdefghijklmnopqrstuvwxyz"

but the following should not:

mutation(["hot", "abcdefg"]); // false because at least one of the second element's characters are not present in the word "hot".

i have used substr() method and it also doesn’t help me i worked out for all except three test cases. P.S . I am trying to approach in a different way.:sweat_smile:

Okay, I see the problem here,

you only check if char in arr1 are equal to char in arr2 one by one (first char equals first char, second char equals second char, …)
You need to check if first char of arr2 is equal to any char of arr1 (using indexOf will help for this)