Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. function mutation(arr) {
  2. newStr = [];
  3. valStr = [];
  4. newStr = arr[0].split('');
  5. valStr = arr[1].split('');
  6.  
  7. //make all lowercase for string
  8. for(i = 0; i < newStr.length; i++){
  9. holder = newStr.shift();
  10. holder = holder.toLowerCase();
  11. newStr.unshift(holder);
  12. }
  13.  
  14. for(i = 0; i < valStr.length; i++){
  15. //make all lowercase for target
  16. holder2 = valStr.shift();
  17. holder2 = holder2.toLowerCase();
  18. valStr.unshift(holder2);
  19. }
  20.  
  21. counter = '0';
  22.  
  23. for(i = 0; i < valStr.length; i++){
  24. n = newStr.indexOf(valStr[i]);
  25. if(n < 0){
  26. return false;
  27. }
  28. counter++;
  29. }
  30. return true;
  31. }
  32.  
  33. mutation(["hello", "hey"]);
  34.  
  35. /*
  36. mutation(["hello", "hey"]) should return false. x
  37. mutation(["hello", "Hello"]) should return true. x
  38. mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true. x
  39. mutation(["Mary", "Army"]) should return true. x
  40. mutation(["Mary", "Aarmy"]) should return true. x
  41. mutation(["Alien", "line"]) should return true. x
  42. mutation(["floor", "for"]) should return true. x
  43. mutation(["hello", "neo"]) should return false. x
  44. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement