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

177
Views
Llamadas de función con la cantidad de argumentos basada en la condición

Tengo una función llamada 'func':

 const otherFunc = (arg1, arg2) => {...} const func = (condition1, condition2) => { condition1 || condition2 ? otherFunc(value, true) : otherFunc(false) }

La forma anterior funciona, pero me pregunto si hay alguna forma de evitar el uso de dos llamadas diferentes a otherFunc. Intenté esto pero no es la sintaxis correcta:

 const func = (condition1, condition2) => { otherFunc((condition1 || condition2) && ...[value, true]) }

Editar: es una función simple para encadenar if y elses:

 function is(value, done) { return { else: (v) => is(done ? value : v, done), if: (condition) => (done || condition ? is(value, true) : is(null)), get: value, }; } const n = 50000; console.log( is('small') .if(n < 1000) .else('big') .if(n > 10000) .else('medium-big') .if(n > 5000) .else('medium-small').get, );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si puede colocar los argumentos en una matriz, puede alternar entre las matrices para distribuirlos en la lista de argumentos.

 otherFunc( ...((condition1 || condition2) ? [value, true] : [false]) );

Dicho esto, no es muy legible. realmente preferiría

 if (condition1 || condition2) { otherFunc(value, true); } else { otherFunc(false); }

Un buen código mantenible no es una competencia de golf: estar lo más SECO posible no siempre es el mejor enfoque.

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!