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

156
Views
How to filter out values in the most concise way?

I have a number of tables to which I push Column Values that I have on file, however I often times end up with multiple of the same value, which doesn't look great. I want to reduce it so that these values can only appear once, I have just done this with another table in my project, but the data is gathered differently for this table and I'm not sure what is the best way to work with my Column Values within the already existing method to filter it to only 1 of each identical value, rather than create a new method, any tips would be appreciated. I'll attach what I did with my other table and my current problem below.

Current Table Data Gathering:

participantDetails(participant) {
  return [ // take all column values, move into arrays, take out duplicates,
    {
      columnName: I18n.t('ccenter.case_file.table.role'),
      columnValue: participant.role,
      dataPointName: 'role'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.company_names'),
      columnValue: participant.companyNames.join(', ') || '-',
      dataPointName: 'companyName'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.aliases'),
      columnValue: participant.aliases.join(', ') || '-',
      dataPointName: 'name'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.birthdates'),
      columnValue: participant.birthdates.join(', ') || '-',
      dataPointName: 'birthdate'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.phones'),
      columnValue: participant.phones.join(', ') || '-',
      dataPointName: 'phone'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.emails'),
      columnValue: participant.emails.join(', ') || '-',
      dataPointName: 'email'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.addresses'),
      columnValue: participant.addresses.join(', ') || '-',
      dataPointName: 'address'
    },
    {
      columnName: I18n.t('ccenter.case_file.table.customer_numbers'),
      columnValue: participant.customerNumbers.join(', ') || '-',
      dataPointName: 'customerNumber'
    }
  ]
},

Previous Table:

   fields.forEach(field => {
    if (participant[field.fieldName].length > 0) {
      const uniqueValues = [];
      const uniqueElements = [];
      participant[field.fieldName].forEach(element => {
        if (!uniqueValues.includes(element.value)) {
          uniqueValues.push(element.value);
          uniqueElements.push(element);
        }
      })
      result.push({
        attributeName: field.fieldName,
        columnName: I18n.t(`ccenter.participant.table.${snakeCase(field.fieldName)}`),
        columnValues: uniqueElements,
        fieldClass: field.fieldClass,
      })
    }
  });
  return result;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Before calling participantDetails(participant) you can remove all duplicates values from participant. First get all keys from participant then check if its value is array, If yes then call removeDuplicates to remove duplicates from that array.

function removeDuplicateValues(p){
    return Object.keys(p).map(k => Array.isArray(p[k]) ? { [k]: removeDuplicates(p[k]) } : { [k]: p[k] }).reduce((acc, item) => ({...acc, ...item}), {});
}

function removeDuplicates(arr){
    return [...new Set(arr)];
}

const participant = {
    role: 'Role_A',
    companyNames: ['Company1', 'Company2', 'Company3', 'Company1'],
    aliases: ['aliases1', 'aliases2', 'aliases3', 'aliases1'],
    birthdates: ['birthdates1', 'birthdates2', 'birthdates3', 'birthdates2'],
    phones: ['phones-1', 'phones-2', 'phones-3', 'phones-2'],
    emails: ['emails-1', 'emails-2', 'emails-3', 'emails-3'],
    addresses: ['addresses-1', 'addresses-2', 'addresses-3', 'addresses-1'],
    customerNumbers: ['customerNumbers-1', 'customerNumbers-2', 'customerNumbers-3', 'customerNumbers-4']
};

const result = removeDuplicateValues(participant);
console.log(result);

Use removeDuplicateValues function inside participantDetails:

participantDetails(participant) {
    participant = removeDuplicateValues(participant);
    return [
        ...
    ];
}
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!