title: Sorting Numbers using Lodash and Typescript
body: <p>I have an angular 2 service <code>apptService</code> that returns <code>Observable&lt;Appointment[]&gt;</code> which I then order using the lodash <code>sortBy</code> function:</p>
  
  <pre><code>class Appointment {
      id: string;
      distance: number;
      appointmentDate: date;
  }
  
  getAppointments(sortOrder) {
     this.appointments = this
       .apptService
       .getAppointments()
       .map(v =&gt; _.sortBy(v, sortOrder));
  }
  </code></pre>
  
  <p>I call <code>getAppointments</code> passing a sort function like so:</p>
  
  <pre><code>getAppointments((app: Appointment) =&gt; app.id);
  getAppointments((app: Appointment) =&gt; app.distance);
  getAppointments((app: Appointment) =&gt; app.appointmentDate);
  </code></pre>
  
  <p>The <code>appointmentDate</code> and <code>id</code> sorts are as expected, but when sorting by <code>distance</code>, the values are ordered alphanumerically ie: 12, 123, 15, 3</p>
  
  <p>For now, I have bodged an unsightly solution using:</p>
  
  <pre><code> getAppointments((app: Appointment) =&gt; {
     // this will only work for appointments up to 100000 miles away
     var s = "00000" + app.distance.toString();
     return s.substr(s.length - 5);
   });
  </code></pre>
  
  <p>but this breaks my pattern, so I am looking for a better solution, or hoping at least to understand why this is happening.</p>
  
  <p>lodash was used for the sort because I liked the syntax and the ease of passing in the sorting arrow function, but am not attached to using it if there is a better solution.</p>
  
  <p>And sorry but no plunker, I could not get lodash and typescript working together at all there.</p>