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

159
Visualizações
What is javascript/typescript equivalent of this python function?

I couldn't convert this syntax to js or ts:

    def get_index(self):
        path = self.get_request_path()
        if "/_async_search" in path and "/_search":
            # no index we wildcard
            return next((sub_part for sub_part in path.split("/") if sub_part != ""), "*")
        return None
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the main complication to do the javascript translation of your python code is to lazy load the list returned by path.split("/") like it's done in your python code.

For that, you can use a generator function like the following:

function* first_substring(path) {
  for(substring of path.split("/")){
    if(substring !== ""){
        yield substring;
    }
    else{
        yield "*";
    }
  }
}

Then your javascript translation would be something like:

function get_index(){
    const path = this.get_request_path();

    if(path.indexOf("/_async_search") !== -1 && "/_search"){
        return first_substring(path).next().value;
    }

    return None

}
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