title: JavaScript anagram comparison
body: <p>I'm trying to compare two strings to see if they are anagrams. </p>
  
  <p>My problem is that I'm only comparing the first letter in each string. For example, "Mary" and "Army" will return true but unfortunately so will "Mary" and Arms." </p>
  
  <p>How can I compare each letter of both strings before returning true/false?</p>
  
  <p>Here's a jsbin demo (click the "Console" tab to see the results"):</p>
  
  <p><a href="http://jsbin.com/hasofodi/1/edit" rel="noreferrer">http://jsbin.com/hasofodi/1/edit</a></p>
  
  <pre><code>function compare (a, b) {
    y = a.split("").sort();
    z = b.split("").sort();
    for (i=0; i&lt;y.length; i++) {
      if(y.length===z.length) {
        if (y[i]===z[i]){
          console.log(a + " and " + b + " are anagrams!");
          break;
        }
        else {
          console.log(a + " and " + b + " are not anagrams.");
          break;
        }
      }
      else {
        console.log(a + " has a different amount of letters than " + b);
      }
      break;
    }
  }
  
  compare("mary", "arms");
  </code></pre>