SHARE
TWEET

Untitled

a guest Jun 24th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             var groupedByFilterId: any = _.groupBy(filterObject, 'questionId');
  2.             //iterate all the questions that the user wanted to filter by
  3.             let obj = undefined;
  4.             let index = 0;
  5.             for (var filterArr of Object.keys(groupedByFilterId)) {
  6.  
  7.                 let innerIndex = 0;
  8.                 for (var currentFilter of groupedByFilterId[filterArr]) {
  9.                     let insertSession = true;
  10.                     //get question id and answer by id
  11.                     let responses = _.groupBy(session.responses, "question_id");
  12.                     //checks if there is an answer of the current filter question
  13.                     if (!responses[currentFilter.questionId]) {
  14.                         insertSession = false;
  15.                         // break; //means the user didn't answer this question in the current session
  16.                     }
  17.                     let currentAnswer: any = responses[currentFilter.questionId][0];
  18.                     //check if the current session is true for each of the filters questions
  19.                     if (!currentAnswer || currentAnswer && currentAnswer.answer.value != currentFilter.value) {
  20.                         //if one is false -> break
  21.                         insertSession = false;
  22.                         // break;
  23.                     }//else means its true
  24.                     if (insertSession) {
  25.                         obj = session;
  26.                         // arrayOfFilterSessions.push(session);
  27.                         // break;
  28.                     }
  29.                     if (groupedByFilterId[filterArr].length - 1 === innerIndex && insertSession === false) {
  30.                         obj = undefined;
  31.                     }
  32.                     innerIndex++;
  33.                 }
  34.                 if (index === Object.keys(groupedByFilterId).length-1 && obj!=undefined) {
  35.                     arrayOfFilterSessions.push(obj);
  36.  
  37.                 }
  38.                 index++;
  39.  
  40.  
  41.  
  42.             }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top