Basic Algorithm Scripting: Mutations - Different way of resolving

Basic Algorithm Scripting: Mutations - Different way of resolving
0

#1

Hey guys!

I just wanted to share a different way of resolving this challenge…
Hope it could help someone!

function mutation(arr) {
  let arr1 = arr[0].toLowerCase().split('');
  let arr2 = arr[1].toLowerCase().split('');
  let count = 0;
  for (let i = 0; i < arr2.length; i++) {
    if (arr1.indexOf(arr2[i]) >= 0){
      count++;
    } else count--;
    
  } if (count == arr2.length) {
    return true;
  } else return false;
}
console.log(
  mutation(["Mary", "Army"]))

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations


#2

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

We have set your post to unlisted. Thanks for your understanding.


unlisted #3