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

239
Views
Sequelize / Vue / Node - I'd like to use a query to filter data after it has been returned to my view

I have a table that tracks all user responses to a quiz. This query will successfully get all the data from that table and put it into my TotalQuizResponses array which I then use in my view:

this.totalQuizResponses = ((await QuizResponsesService.index()).data)

However, I'd also like to display the total number of matches in my view. I know this SQL query successfully gets that total number of matches from the table data:

SELECT count(*)
FROM QuizResponses A, QuizResponses B
WHERE A.answerKey = B.answerKey AND A.QuizId = B.QuizId AND A.UserId < B.UserId

I don't want to have to do another service call just to get the count on filtered data that I already have inside my view. Is there a way to somehow filter the data from within the view? I'm unsure how to replicate this logic using pure JavaScript. Thanks for reading.

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

0

If you need the exact same query on unfiltered data:

countResponses(this.totalQuizResponses);

function countResponses(quizData) {
  let counter = 0;

  for (const quizResponseA of quizData) {
    for (const quizResponseB of quizData) {
      if (quizResponseA === quizResponseB) { continue; }

      const isSameAnswerKey = quizResponseA.answerKey === quicResponseB.answerKey;
      const isSameQuizId = quizResponseA.QuizId === quizResponseB.QuizId;
      const isSameUser = quizResponseA.UserId === quizResponseB.UserId;

      if (isSameAnswerKey && isSameQuizzId && isSameUser) {
        counter++;
      }
    }
  }

  return counter;
}

If you already filtered your data with the same query, this.totalQuizResponses.length is the same as a counter for all the data you have locally

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!