Advertisement
ErolKZ

Untitled

Aug 25th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2. var isAnagram = function (test, original) {
  3.  
  4.  
  5. if (original.length !== test.length) {
  6.  
  7. return false;
  8.  
  9. }
  10.  
  11.  
  12.  
  13. let matches = 0;
  14.  
  15. test = test.toUpperCase();
  16.  
  17. original = original.toUpperCase();
  18.  
  19. original = original.split('');
  20.  
  21. test = test.split('');
  22.  
  23.  
  24.  
  25. for (let i = 0; i < original.length; i++) {
  26.  
  27.  
  28. for (let j = 0; j < test.length; j++) {
  29.  
  30. if (original[i] === test[j]) {
  31.  
  32. test.splice(j, 1);
  33.  
  34. matches++;
  35.  
  36. }
  37.  
  38. }
  39.  
  40. }
  41.  
  42.  
  43.  
  44. if (matches === original.length) {
  45.  
  46. return true;
  47.  
  48. } else {
  49.  
  50. return false;
  51.  
  52. }
  53.  
  54.  
  55.  
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement