Algorithm Challenge: Mutations feedback request (spoilers)

This problem took me some time, and I’m curious if my solution is inelegant/inefficient. I would welcome any feedback, or suggestions for improvement.

function mutation(arr) {
  var a = arr[1].toLowerCase().split('');
  var b = arr[0].toLowerCase();
  var i = 0;
  while ((b.indexOf(a[i]) >= 0) && (i < a.length)) {
  if (i === arr[1].length) {
    return true;
  } else return false;

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

You can replace the if-else block with this line:

return i === arr[1].length;

You can also replace (b.indexOf(a[i]) >= 0) with the more descriptive


I think you should have named your variables with names like first / second (or at least assign the first array to a).

Thank you for the simplifying suggestions - as regards the includes() method, I was avoiding using it because the prompt refers to the indexOf() method, and I don’t think includes() is described anywhere in the course work up to this point.