I messed up with the hasOwnProperty()'s method

Tell us what’s happening:
i expected that tv.hasOwnProperty(rv[o]) would return true if each of tv properties were present at the rv properties, but it didn’t happened… Do you know why?

Your code so far

function mutation(arr) {
  var err = arr[0].split("");
  var irr = arr[1].split("");
  var rv = {};
  var tv = {};
  for (var e = 0; e < irr.length; e++) {
    tv[irr[e].toLowerCase()] = irr[e].toLowerCase();
  }
  for (var i = 0; i < err.length; i++) {
    rv[err[i].toLowerCase()] = err[i].toLowerCase();
  }
  var match;
  for (var o = 0; o < irr.length; o++) {
    if (rv.hasOwnProperty(tv[o])) {
      match = true;
    } else {
      match = false;
    }
  }
  return match;
}

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

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/mutations

If I’m not mistaken, and according to your code, tv is an object that looks like this (with the hello example):

{
  e: "e",
  h: "h",
  l: "l",
  o: "o"
}

o is an integer, as such, and using the hello example:

tv[0]; // undefined
tv[1]; // undefined
// .. etc

tv['o'] // 'o'
tv['e'] // 'e'
// .. etc

I think there is a good chance that you already know what the issue is, so I’ll leave it at that. :slight_smile: Good luck!

1 Like

Thanks, but i think i can learn more about JS if i follow workin till the code works so ill keep tryin

Yes! Keep working at it is a good idea—what I meant is that I won’t comment more so that you can try it yourself and learn from it. :smile:

Good luck and happy coding!

1 Like