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

136
Views
What's the best way to rewrite this?

I've wrote search query filter, but it seems complicated and long to me and I suppose there's another way to write it. So could you show your example?

return this.myCourses.filter(c => {
    return c?.purchased_course?.title.toLowerCase().startsWith(this.searchQuery) ||
      c?.purchased_course?.user?.first_name.toLowerCase().startsWith(this.searchQuery) ||
      c?.purchased_course?.user?.last_name.toLowerCase().startsWith(this.searchQuery)
  })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Object destructuring

Unpack fields from objects passed as a function parameter.

const startsWithQuery = p => p?.toLowerCase().startsWith(this.searchQuery);

return this.myCourses.filter(({purchased_course: {title, user: {first_name, last_name} = {}}}) => [title, first_name, last_name].some(startsWithQuery));
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!