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

123
Views
Determine if all object properties are equal

I am creating the boolean hasMultipleCoverageLines to determine if different coverageLineName values exist on the items within coverageLines. Is there a way to simplify this expression so i don't have to explicitly check for each coverageLineName?

this.hasMultipleCoverageLines = !this.coverageLines.every((x) => x.coverageLineName === "Medical")
        && !this.coverageLines.every((x) => x.coverageLineName === "Dental")
        && !this.coverageLines.every((x) => x.coverageLineName === "Vision")
        && !this.coverageLines.every((x) => x.coverageLineName === "Life");
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

A set will enforce uniqueness. Put the names in a set, and see if the count > 1.

let names = this.coverageLines.map(x => x.coverageLineName);
let set = new Set(names);
this.hasMultipleCoverageLines = set.size > 1;

With this ["Dental", "Dental", "Dental"] will produce a set of size 1, but ["Dental", "Vision", "Dental"] will produce a set of size 2, and so on...

about 4 years ago · Juan Pablo Isaza Report

0

You could just check if any line is different than previous.

const hasMultipleCoverageLines = (lines) => {
  return lines.some((line, i) => {
    return i > 0 && line.coverageLineName !== lines[i - 1].coverageLineName;
  });
};
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!