Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getUnpublishedString() {
- const { unpublishedAnswerNames } = this.props;
- const unpub = [];
- unpublishedAnswerNames.forEach(item => {
- const elem = unpub.find(elem => elem.name === item);
- if (elem) {
- elem.count += 1;
- } else {
- unpub.push({ name: item, count: 1 });
- }
- });
- let retString = unpub.length === 0 ? 'No Unpublished Answers' : '';
- unpub.forEach(item => {
- retString +=
- (retString.length > 0 ? ', ' : '') +
- this.formatQuestionName(item.name) +
- (item.count > 1 ? '(' + item.count + ')' : '');
- });
- return retString;
- }
- formatQuestionName = name => {
- let ret = name.substring(0, 1).toUpperCase() + name.substring(1);
- for (let ii = 1; ii < ret.length; ii++) {
- const char = ret.substring(ii, ii + 1);
- if (char === char.toUpperCase()) {
- ret = ret.substring(0, ii) + ' ' + ret.substring(ii);
- ii += 1;
- }
- }
- return ret;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement