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

172
Views
Remove duplicate words except numbers

I need to remove duplicate words in a string, but not the numeric characters.

Here's an example of text that I need to convert and keep the numeric characters. Any suggestions on how to handle this?

String example: "Rim - Rim Black 28H 700mm x 700mm"

  static removeDuplicateWords = (statement: string) => {
    return statement
      .split(" ")
      .filter((item, pos, self) => {
        return self.indexOf(item) === pos;
      })
      .join(" ");
  };

Current Results: - Rim Black 28H x 700mm

Expected results: - Rim Black 28H 700mm x 700mm

Thanks for the help

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

0

Use a regular expression to test if the word contains a digit.

static removeDuplicateWords = (statement: string) => {
  return statement
    .split(" ")
    .filter((item, pos, self) => item.match(/\d/) || self.indexOf(item) === pos)
    .join(" ");
};

about 4 years ago · Juan Pablo Isaza Report

0

From your example, you can create a set of the split string and join it again.

console.log(Array.from(new Set("Rim - Rim Black 28H 700mm x 700mm".split(' '))).join(' '))

// print 'Rim - Black 28H x 700mm'

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!