Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getUnpublishedString() {
  2.     const { unpublishedAnswerNames } = this.props;
  3.     const unpub = [];
  4.  
  5.     unpublishedAnswerNames.forEach(item => {
  6.       const elem = unpub.find(elem => elem.name === item);
  7.  
  8.       if (elem) {
  9.         elem.count += 1;
  10.       } else {
  11.         unpub.push({ name: item, count: 1 });
  12.       }
  13.     });
  14.  
  15.     let retString = unpub.length === 0 ? 'No Unpublished Answers' : '';
  16.  
  17.     unpub.forEach(item => {
  18.       retString +=
  19.         (retString.length > 0 ? ', ' : '') +
  20.         this.formatQuestionName(item.name) +
  21.         (item.count > 1 ? '(' + item.count + ')' : '');
  22.     });
  23.  
  24.     return retString;
  25.   }
  26.  
  27.   formatQuestionName = name => {
  28.     let ret = name.substring(0, 1).toUpperCase() + name.substring(1);
  29.  
  30.     for (let ii = 1; ii < ret.length; ii++) {
  31.       const char = ret.substring(ii, ii + 1);
  32.  
  33.       if (char === char.toUpperCase()) {
  34.         ret = ret.substring(0, ii) + ' ' + ret.substring(ii);
  35.         ii += 1;
  36.       }
  37.     }
  38.  
  39.     return ret;
  40.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement