Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Lodash: _Filter, pero devuelve una matriz de objetos con claves específicas

Estoy haciendo una función que compara dos matrices de objetos y devuelve dos matrices de subconjuntos de objetos. La primera matriz devuelta es un conjunto de objetos que no se incluyeron en la matriz pasada dentro de la segunda propiedad, y la segunda matriz devuelta es un conjunto de objetos que no se incluyeron en la primera matriz pero ahora se incluyen en la segunda.

Esto funciona, sin embargo, quiero agregar una funcionalidad adicional para devolver la segunda matriz con claves específicas. ¿Hay alguna forma de utilizar la funcionalidad "pickBy" de lodash dentro de la función de filtro, o tendré que crear una sección recursiva adicional?

 function extract_removed_new (before, after, matching, pickBy = []) { let before_ = cloneDeep(before) let new_ = _.filter(after, (item) => { let index_ = _.findIndex(before_, function (i) { return _.get(i, matching) == _.get(item, matching) }) if(index_ !== -1) { before_.splice(index_, 1) return false } if(pickBy.length > 0) { return _.pickBy(item, function(value, key) { if(key in pickBy) { return true } }); } return true }) return [before_, new_]

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usando lodash compact, con map pude obtener exactamente lo que necesitaba.

 function extract_removed_new (before, after, matching, pickBy = []) { let before_ = cloneDeep(before) let new_ = _.compact(_.map(after, (item) => { let index_ = _.findIndex(before_, function (i) { return _.get(i, matching) == _.get(item, matching) }) if(index_ !== -1) { before_.splice(index_, 1) return false } if(pickBy.length > 0) { return _.pickBy(item, function(value, key) { if(pickBy.includes(key)) { return true } }); } return item })) return [before_, new_]

}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!