Mutations help 22

I don’t understand, why why the compiler throws an error “TypeError: unknown: undefined has no properties”. The site pytotutor all works fine.

function mutation(arr) {
  var arr1 = arr.shift().toString().split(''); 
  var arr2 = arr.pop().toString().split(''); 
  var post = arr2.length;
  var cash = 0;
  var count = 0;

  for (var i = 0; i < arr2.length; i++) {
    cash = arr2[i];

    for (var a = 0; a < arr1.length; a++)
      if (cash == arr1[a]) {
        count++;
      }
    }

    if (count == post){
      return true;
    } else {
     return false;
    }  
}
mutation(["hello", "Hello"]);

Your browser information:

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

Link to the challenge:

I’ve formatted the code to make it slightly easier to read and see where the possible cause of the error is: there is a missing opening bracket on inner for loop.

Thank you for your help/

1 Like