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

145
Views
Mandatory console log?

function removeExtraSpace(input) {
  const pattern = /(?:<p><br><\/p>)+$|(<p> *<\/p>)+$/g;
  while(pattern.test(input.trimEnd()) == true){
      input = input.trimEnd().split(pattern)[0]
  }
  return input;
}

console.log(removeExtraSpace("<p>test</p><p>test2</p><p><br></p><p><br></p><p></p><p> </p><p>  </p> "));

Input example:

"<p>test</p><p>test2</p><p><br></p><p><br></p><p></p><p> </p><p>  </p> "

Expected output:

"<p>test</p><p>test2</p>"

Returns:

"<p>test</p><p>test2</p><p><br></p><p><br></p><p></p><p> </p>"

But if I add a console log to my loop, it starts to work. What am I bastardizing here?

function removeExtraSpace(input) {
  const pattern = /(?:<p><br><\/p>)+$|(<p> *<\/p>)+$/g;
  while(pattern.test(input.trimEnd()) == true){
      input = input.trimEnd().split(pattern)[0]
      console.log(pattern.test(input.trimEnd()))
  }
  return input
} 

console.log(removeExtraSpace("<p>test</p><p>test2</p><p><br></p><p><br></p><p></p><p> </p><p>  </p> "));

about 4 years ago · Juan Pablo Isaza
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!