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

111
Views
Función inversa de _.invertBy() de lodash

¿Cuál es la función inversa del método _.invertBy() de lodash?

Quiero hacer un viaje de ida y vuelta y convertir un objeto más tarde a la misma forma después de invertirlo. Pero si lo hago

 > _.invertBy({apple: 'fruit', pear: 'fruit'}) { fruit: [ 'apple', 'pear' ] } > _.invertBy({ fruit: [ 'apple', 'pear' ] }) { 'apple,pear': [ 'fruit' ] }

y { 'apple,pear': [ 'fruit' ] } no es lo mismo que {apple: 'fruit', pear: 'fruit'} .

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

0

Uno puede piratear el código fuente de invertBy de github y obtener algo como

 function invertBackBy(object, iteratee = _.identity) { const result = {} Object.keys(object).forEach((key) => { object[key].map(iteratee).forEach((value) => { result[value] = key }) }) return result }

o si lo que querías era una sola línea lodash, creo que no hay nada más simple que

 oinv => _.reduce(oinv, (acc, values, key) => _.assign(acc, _.fromPairs(_.map(values, value => [value, key]))), {})

ver violín para un ejemplo.

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!