manudude03

Mutation

Aug 19th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mutation(arr)
  2. {
  3.     // turn the elements lower case to ignore case, and split into characters
  4.     var str1 = arr[0].toLowerCase().split("");
  5.     var str2 = arr[1].toLowerCase().split("");
  6.     // loop through the second first since all letters there must be present in first
  7.     for (var i=0; i<str2.length; i++)
  8.     {
  9.         // flagging a match
  10.         var match=false;
  11.         for (var j=0; j<str1.length; j++)
  12.         {
  13.             if(str1[j]==str2[i])
  14.             {
  15.                 match=true;
  16.             }
  17.         }
  18.         // if a match wasn't found, then this should return false (breaking the function loop)
  19.         if (!match) return false;
  20.     }
  21.     return true;
  22. }
  23.  
  24. mutation(["hello", "hey"])
Advertisement
Add Comment
Please, Sign In to add comment