Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda