title: How to implement a sort by mechanism?
body: <p>the array.sort() is taking a function that returns a number. so usually something like this </p>
  
  <pre><code>myArray.sort((item1, item2) =&gt; a &lt; b);
  </code></pre>
  
  <p>alright, what i want to have is:</p>
  
  <pre><code>myArray.sort(by(obj =&gt; obj.id))
  </code></pre>
  
  <p>so: </p>
  
  <ul>
  <li>I have an argument that is a function that returns a number from an any</li>
  <li>i return a function that has 2 arguments (the ones to be compared) and returns a number</li>
  <li>this function compares the 2 results</li>
  </ul>
  
  <p>it should look somehow like this... unfortunately I can't get it to work with various approaches.</p>
  
  <pre><code>by = (getter : any =&gt; number): ((any, any) =&gt; number) =&gt; (x,y) =&gt; {
    var xValue = getter(x);
    var yValue = getter(y);
  
    if (xValue &gt; yValue)
      return 1;
    else (xValue &lt; yValue)
      return -1;
    else return 0;
  }
  </code></pre>
  
  <p>am I on the right track here?
  thanks!</p>