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

106
Views
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 answers
Answer question

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