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

138
Vistas
Conditionally rendering an Array Method using Ternary Operator

This is a strange situation but utilizing the ternary operator to determine my array method would allow for much dryer code.

The goal:

const result = array. (isTrue ? some : every) (item) => {A lot of logic}

The above code obviously wont work but I wanted to see if there was some syntax that would allow something like this?

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

0

You can use the bracket notation to access the method conditionally:

const method = (isTrue, array) => array[isTrue ? 'some' : 'every'](item => item)

const arr = [0, 1, 2]

console.log(method(true, arr)) 
console.log(method(false, arr))

about 4 years ago · Juan Pablo Isaza Denunciar

0

I'd just do it this way:

const myLogic = (item) => { a lot of logic };

const result = isTrue ? array.some(myLogic) : array.every(myLogic)
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