Help me pass this test plz

Tell us what’s happening:
Plz help me all the test pass but this one didn’t because it has a repeating character. I am trying to solve it wilthout javaScripts own fuctions.

  **Your code so far**

function mutation(arr) {
let second = arr[1].toLowerCase()
let first = arr[0].toLowerCase()
let newArr = [];

for(let i = 0; i < second.length; i++) {
  for(let j = 0; j < first.length; j++) {
  if(second[i] === first[j]) {
  } else if(second[i] === first[j]) {
  } else {

let trueArray = [];

for(let i = 0; i < newArr.length; i++) {
  if(newArr[i] === true){

if (second.length === trueArray.length) {
  return true;
} else {
  return false


console.log(mutation(["floor", "for"]));
  **Your browser information:**

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

Challenge: Mutations

Link to the challenge:

Can you walk us through your logic?

It seems that you are trying to see if there are character matches and see if the number of matches is the same as the length of the second input string. I don’t think that logic is sound. I think that it works sometimes, but breaks down when there are duplicate letters. Note that when you run this:

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

It matches each of those os in “floor”, even though “for” only needs one. Consequently, trueArray.length ends up being 4. Note that this will return true just fine:

mutation(["flor", "for"]);

I think you need to rethink your algorithm.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.