Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
Sort desc if item is included in an array with lodash or with out

I have a array of objects like so:

const attendList = [
{
  "first": "John",
  "last": "Foo",
  "uid": "-Lz8YxIYM_4L3f9nKM70",
},
{
  "first": "Jake",
  "last": "Foo",
  "uid": "-Lz8YxIYM_4L3fsdfM70",
}
...
]

Then I have an array containing the keys

const found = ["-Lz8YxIYM_4L3fsdfM70", "-Lz8YxIYM_4L3fsdf333", "-Lz8YxIYM_r4hfsdf333" ]

I want to sort attendList by placing the items that are in found at the bottom of the list. My incorrect attempt (using lodash) is:

let SetItemsLast = _.sortBy(attendList, ({uid}) => found.includes(uid) ? 0:1);

I'm obviously not doing it correctly. How can I resolve this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this if you need to keep the attendList items in order otherwise.

  let SetItemsLast = attendList.sort((a, b)=>{
    if(found.includes(a.uid)){
      return 1;
    }
    if(found.includes(b.uid)){
      return -1;
    }
    return 0;
  });

If you don't care whether the items at the bottom remain in order, you can just do this.

  let SetItemsLast = attendList.sort((a, b)=>{ return found.includes(b.uid) ? -1:0; });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda