title: Javascript custom sort function depending on user input
body: <p>I'm trying to make a custom compare callback function for the Javascript <code>array.sort</code> method. It should return a value depending on user input.</p>
  
  <p>When that callback function is called, it should wait until the user clicks a button. Depending on the clicked button the function would know which of the two elements is bigger and return the corresponding result (1 or -1).</p>
  
  <p>The only way I know to wait for user input is with an event listener function, but I don't know how to adapt this to the custom function I have to pass to the <code>array.sort()</code> method.</p>
  
  <p>Here is the code I'm trying with; I know this code won't work:</p>
  
  <pre><code>var array=["a","b","c"];
  array.sort(function(a,b){
      var result;
  
      $("#button1").click(function(){
          result = 1;
      });
  
      $("#button2").click(function(){
          result = -1;
      });
      return result;
  }
  </code></pre>
  
  <p>I'm starting to think it's impossible to use the <code>array.sort</code> function for this purpose.</p>
  
  <p>Is there a way to do this?</p>