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

174
Views
¿Hay un puerto de JavaScript de las funciones en la biblioteca estándar de C?

Estoy portando un código C a JavaScript. Me gustaría no tener que implementar funciones básicas como strcspn yo mismo

 const strcspn = (a, b) => { for (let [index, c] of [...a].entries()) { if (b.includes(c)) { return index } } return a.length }

¿Hay algún proyecto del que pueda copiarlos o que pueda importar?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No hay una biblioteca en Javascript que proporcione las mismas funciones de la biblioteca estándar de C (que yo sepa, al menos).

Por lo tanto, debe volver a escribir las funciones usted mismo (no es particularmente difícil, ya que Javascript tiene muchas funciones integradas que pueden ayudarlo).

Mejor aún : no use las funciones estándar de C en Javascript: modifique el código C directamente para escribir un código Javascript más idiomático. Lo que quiero decir:

 // a C code that uses `strtok()` to split a string may be rewritten in JS as: const splitted = str.split(" "); // it's cleaner and you don't need to rewrite `strtok()` in JS

NOTA: su implementación de strcspn() es incorrecta. La implementación correcta en Javascript sería:

 function strcspn(dest, src) { let res = 0; for (let i = 0; i < dest.length; i += 1) { if (src.includes(dest.charAt(i))) { break; } res += 1; } return res; }
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!