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

111
Vistas
Swapping out Constants for a Function

I'm trying to refactor the following code, which depending on the top level domain of the recipients email, changes where you click through to in my button. I currently do this with two consts, which I need to refactor into only one.

 const CCENTERURL_AT= `${HOSTURL_AT}/ccenter/zendesk/landing/`;
    const CCENTERURL = `${HOSTURL}.com/ccenter/zendesk/landing/`;

 const recipientEmail = data.ticket.recipient;
      var cCenterUrl;
      if(recipientEmail.indexOf(".com") > 0) 
      {
        cCenterUrl = getCcenterUrl(zendeskID)
      }else{
       cCenterUrl = getAustrianCcenterUrl(zendeskID)
      }



    function getCcenterUrl(ticketID) {
      const cCenterTicketUrl =  CCENTERURL + ticketID ;
      return cCenterTicketUrl;
    }


     // Get Austrian Ccenter Ticket Url using Zendesk ticket ID
    function getAustrianCcenterUrl(ticketID) {
      const cCenterTicketUrlAustria =  CCENTERURL_AT + ticketID ;
      return cCenterTicketUrlAustria;
    }

I know I should be able to create a function which will take recipient Email`s top-level domain as parameter and return appropriate URL for CCENTERURL. But no matter what I've tried its become overcomplicated or hasn't worked. I would be interested to hear peoples opinions on either how I can achieve my goal or even how it would be better to go about this!

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

0

So you basically want to combine these into one function and use a string template like this.

const HOSTURL = 'example.com/'
const HOSTURL_AT = 'example.au/'

const reAu = /\.au$/;
const getTicketURL = (
  (mail, id) => `${ reAu.test(mail) > 0 ? HOSTURL : HOSTURL_AT }ccenter/zendesk/landing/${id}`
);


// Test AU
console.log(getTicketURL('foo@google.com.au', 'ABC1231'))

// Test US
console.log(getTicketURL('foo@google.com', 'ABC1231'))

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