Mutations, I made it.Who persevers wins

Mutations, I made it.Who persevers wins
0.0 0

#1

Hello friends here a write my code, just in case could help someone.

function mutation(arr) {
var string1 = arr[0].toLowerCase();
var string2 = arr[1].toLowerCase();
var str1 = string1.split("");
var str2 = string2.split("");
var response = “”;
if(str1.length > str2.length){
for(var i = 0; i< str2.length; i++){
if (str1.indexOf(str2[i])>=0){
response = true;
}else{
response = false;
i = str2.length;
}
}

/--------------------------------------/
}else if(str1.length < str2.length||str1.length === str2.length){
for(var j = 0; j<str1.length; j++){
if(str2.indexOf(str1[j])>=0){
response = true;
}else{
response = false;
j = str1.length;
}
}

}return response;

}

mutation([“hello”, “Hello”]);


#2

Well done! Hard work pays.

May I suggest when you post code in the forum to do the following:

  1. Use triple backticks (```) before and after your code to make your code more readable

  2. Hide your code using the “Hide Details” or “Blur Spoiler” features in the Reply settings.

  3. Use tabs and spaces in your code to make it more readable. If you’re going to be coding, an important part of it is making your code easily readable for others and for yourself later.

Here’s an example using your code. I applied all 3 points above:

Summary
function mutation(arr) {
  var string1 = arr[0].toLowerCase();
  var string2 = arr[1].toLowerCase();
  var str1 = string1.split("");
  var str2 = string2.split("");
  var response = "";
  if ( str1.length > str2.length ) {
    for ( var i = 0; i < str2.length; i++ ) {
      if ( str1.indexOf(str2[i]) >= 0 ) {
        response = true;
      }
      else {
        response = false;
        i = str2.length;
      }
    }

/*--------------------------------------*/ 
      }
      else if ( str1.length < str2.length || str1.length === str2.length ) {
        for ( var j = 0; j < str1.length; j++ ) {
        if ( str2.indexOf(str1[j]) >= 0 ) {
          response = true;
        }
      else {
        response = false;
        j = str1.length;
      }
    }
  }
return response;
}

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

Isn’t that much more pleasant to read?