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

166
Views
¿Es posible hacer una función a partir del código y hacerlo más corto?

tengo estas lineas de codigo

 let value = productDetails.recentPurchaseDate; if (!productDetails.salesPrice && !productDetails.recentPurchaseDate) { value = false; } if (!productDetails.presentEstimatedValue) { value = true; }

¿Es posible refactorizar, necesito hacerlo funcionar y estos dos IF? Gracias por adelantado

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

0

En general, no creo que esté bien diseñado si las condiciones, pero no conozco los requisitos de su negocio. Probemos con algo como esto

 let value = productHasRecentPurchaseDate(productDetails); //name should math your business goal function productHasRecentPurchaseDate(productDetails) { if (!productDetails.salesPrice && !productDetails.recentPurchaseDate) { return false; } else if (!productDetails.presentEstimatedValue) { return true; } else { return /*you need all if statement path to return some value, this is last one, please provide what those statements should return if both previous conditions fail*/; } }
about 4 years ago · Juan Pablo Isaza Report

0

Puedes hacerlo así

 function getValue({ salesPrice, recentPurchaseDate, presentEstimatedValue }) { if (!salesPrice && !recentPurchaseDate) return false; if (!presentEstimatedValue) return true return recentPurchaseDate }

y entonces

 let value = getValue(productDetails);
about 4 years ago · Juan Pablo Isaza Report

0

¿Algo como eso?

 const value = yourNewFn(); function yourNewFn() { if (!productDetails.salesPrice && !productDetails.recentPurchaseDate) { value = false; } if (!productDetails.presentEstimatedValue) { value = true; } return value; }
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!