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

164
Views
¿Cuál es el equivalente de javascript/mecanografiado de esta función de python?

No pude convertir esta sintaxis a js o 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 answers
Answer question

0

Creo que la principal complicación para hacer la traducción de javascript de su código python es cargar de forma diferida la lista devuelta por path.split("/") como se hace en su código python.

Para eso, puede usar una función generadora como la siguiente:

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

Entonces su traducción de javascript sería algo como:

 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 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!