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

111
Vistas
A function that takes one line of JavaScript and returns a possible line comment trimmed

If the line contains no line comment, null should be returned.

cutComment('let foo; // bar') should return 'bar', but its returning 'let foo; // bar'.

function cutComment(comment) {
  if (comment === null) {
    return null;
  } else {
    return comment.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '').trim();
  }
}

console.log(cutComment('let foo; // bar'));

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

0

changed the regex to match anything that comes after //

function cutComment(comment) {
 if(!comment) return null

 let match = comment.match(/(?<=\/\/).+/)
 if(match.length > 0 ) {
    return match[0]
  }else{
   return null
 }
}

console.log(cutComment('let foo; // bar'));

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