Implement the Mutations Algorithm - Implement the Mutations Algorithm

Tell us what’s happening:

I feel like I am not matching with any letters, only the correpsonding letter with the “i” number in the 2 arrays, any help? Thanks.

Your code so far

function mutation (sentence1, sentence2){

const char1 = sentence1.toLowerCase();
const char2 = sentence2.toLowerCase();

const char1lower = char1.split("");
const char2lower = char2.split("");


let result = "";
for(let i =0; i <= char1lower.length || i <= char2lower.length; i++){
if(char1lower[i] == char2lower){  

result = "true";
 
} else{result = "false"}

 
return result;
}

}

console.log(mutation("z", "qrstuz")); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Implement the Mutations Algorithm - Implement the Mutations Algorithm

Your function starts on the wrong foot.

You have 2 parameters:

function mutation (sentence1, sentence2)

The instructions say the function takes 1 array as an argument which you can see from the test functions, for example:

mutation(["floor", "for"]) 

The test function call you have used does not match the requirements of the question:

console.log(mutation("z", "qrstuz")); 

There may be other things wrong as well but you need to start on the right basis and move forward. Please make these changes and try again. You can post your updated code to this thread if you are still having probems.

Thanks, I have renewed the code as following, I am checking if there is any repeated element in the array that i combined within the array, but it is not working, am I in the right direction?

function mutation (sentence){

let char1 = sentence[0].toLowerCase().split(“”);

let char2 = sentence[1].toLowerCase().split(“”);

char1.push(char2);

let char = char1;

console.log(char);

let result = “”;

for(let i =0; i <= char.length; i++){

for(let j =i + 1; j <= char.length; j++){

if(char[i] === char[j]){

result = “true”

}else {

result = “false”

}

}

}

return result;

}

console.log(mutation([“hello”, “Hello”]));

Pleas update the post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

function mutation (sentence){

let char1 = sentence[0].toLowerCase().split(“”);

let char2 = sentence[1].toLowerCase().split(“”);

char1.push(char2);

let char = char1;

console.log(char);

let result = “”;

for(let i =0; i <= char.length; i++){

for(let j =i + 1; j <= char.length; j++){

if(char[i] === char[j]){

result = “true”

}else {

result = “false”

}

}

}

return result;

}

console.log(mutation([“hello”, “Hello”]));

thank you!

I see one thing here, you put a value in result with quotes, that means this is not a boolean but a string, what do the user stories ask you to return? a boolean or a string?

you should be able to pass some tests at that point, but for all of them you need to also have the correct logic and I have not checked that carefully yet, I have doubts tho, because you are checking the letters in a way that does not see is going to work
also what is the line char1.push(char2) doing? why are you putting all the letters inside one word?

I also see curly quotes, but I suppose that is an affectation from posting on the forum, but in case, you must use straight quotes, these ones → ""