DEV Community

Ariel Calisaya
Ariel Calisaya

Posted on

Answer: Ordenar una matriz de objetos por valores de propiedad

It's beautiful and genuine

Here's a more flexible version, which allows you to create reusable sort functions, and sort by any field.

const sort_by = (field, reverse, primer) => {

  const key = primer ?
    function(x) {
      return primer(x[field])
    } :
    function(x) {
      return x[field]
    };

  reverse = !reverse ?

Top comments (0)