File size: 849 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const calcTotalDiscussion = (comments) =>
   comments.reduce(
      (count, item) => count + Object.values(item.replies).length + 1,
      0
   );

export const calculateReaction = (heart, unicorn, saved) => {
   const heartArr = heart || [];
   const unicornArr = unicorn || [];
   const savedArr = saved || [];

   return heartArr.length + unicornArr.length + savedArr.length;
};

export const claculateWrittenComments = (commentArr, userId) => {
   let writtenComments = 0;

   commentArr.forEach((commentItem) => {
      if (commentItem.userId === userId) {
         writtenComments++;
      }

      const repliedComments = Object.values(commentItem.replies);
      repliedComments.forEach((comment) => {
         if (comment.userId === userId) {
            writtenComments++;
         }
      });
   });

   return writtenComments;
};