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

173
Vistas
Is there a JavaScript port of the functions in the C standard library?

I am porting some C code to JavaScript. I would like to not have to implement basic functions like strcspn myself

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

Is there a project I can copy them from or that I could import?

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

0

There is no library in Javascript that provides the same functions of the C Standard Library (that I'm aware of, at least).

So you have to rewrite the functions yourself (not particularly difficult, as Javascript has many builtins that may help you).

Better yet: don't use C standard functions in Javascript: modify the C code directly in order to write more idiomatic Javascript code. What I mean:

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

NOTE: your implementation of strcspn() is wrong. The correct implementation in Javascript would be:

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