SHOW:
|
|
- or go back to the newest paste.
| 1 | function sprintReview(input) {
| |
| 2 | let n = Number(input.shift()); | |
| 3 | let participantsCollections = {};
| |
| 4 | let commandParser = {
| |
| 5 | 'Add New': addTask, | |
| 6 | 'Change Status': changeStatus, | |
| 7 | 'Remove Task': removeTask, | |
| 8 | } | |
| 9 | ||
| 10 | let totalPoints = 0; | |
| 11 | let toDoPoints = 0; | |
| 12 | let inProgress = 0; | |
| 13 | let codeReview = 0; | |
| 14 | let donePoints = 0; | |
| 15 | ||
| 16 | for (let index = 0; index < n; index++) {
| |
| 17 | const [ assignee, taskId, title, status, estimatedPoints ] = input.shift().split(':');
| |
| 18 | if (participantsCollections.hasOwnProperty(assignee)) {
| |
| 19 | let task = {'taskId': taskId, 'title': title, 'status': status, 'estimatedPoints': Number(estimatedPoints)};
| |
| 20 | participantsCollections[assignee].push(task) | |
| 21 | } else {
| |
| 22 | participantsCollections[assignee] = [ {'taskId': taskId, 'title': title, 'status': status, 'estimatedPoints': Number(estimatedPoints)} ];
| |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | for (const inputLine of input) {
| |
| 27 | let commandInfo = inputLine.split(':');
| |
| 28 | let command = commandInfo[0]; | |
| 29 | commandParser[command](...commandInfo.slice(1)); | |
| 30 | } | |
| 31 | ||
| 32 | function addTask(assignee, taskId, title, status, estimatedPoints) {
| |
| 33 | if (!participantsCollections.hasOwnProperty(assignee)) {
| |
| 34 | console.log(`Assignee ${assignee} does not exist on the board!`)
| |
| 35 | } else {
| |
| 36 | let newTask = {'taskId': taskId, 'title': title, 'status': status, 'estimatedPoints': Number(estimatedPoints)}
| |
| 37 | participantsCollections[assignee].push(newTask) | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | function changeStatus(assignee, taskId, newStatus) {
| |
| 42 | if (!participantsCollections.hasOwnProperty(assignee)) {
| |
| 43 | console.log(`Assignee ${assignee} does not exist on the board!`);
| |
| 44 | } else if (participantsCollections[assignee].filter(task => task.taskId === taskId).length === 0) {
| |
| 45 | console.log(`Task with ID ${taskId} does not exist for ${assignee}!`);
| |
| 46 | } else {
| |
| 47 | for (const task of participantsCollections[assignee]) {
| |
| 48 | if (task.taskId === taskId) {
| |
| 49 | task.status = newStatus; | |
| 50 | } | |
| 51 | } | |
| 52 | } | |
| 53 | } | |
| 54 | ||
| 55 | function removeTask(assignee, index) {
| |
| 56 | if (!participantsCollections.hasOwnProperty(assignee)) {
| |
| 57 | console.log(`Assignee ${assignee} does not exist on the board!`);
| |
| 58 | } else if (index < 0 || index >= participantsCollections[assignee].length) {
| |
| 59 | console.log(`Index is out of range!`) | |
| 60 | } else {
| |
| 61 | participantsCollections[assignee].splice(index, 1); | |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | for (const key in participantsCollections) {
| |
| 66 | for (const task of participantsCollections[key]) {
| |
| 67 | totalPoints += Number(task.estimatedPoints); | |
| 68 | if (task.status === 'ToDo') {
| |
| 69 | toDoPoints += Number(task.estimatedPoints); | |
| 70 | } else if (task.status === 'In Progress') {
| |
| 71 | inProgress += Number(task.estimatedPoints); | |
| 72 | } else if (task.status === 'Code Review') {
| |
| 73 | codeReview += Number(task.estimatedPoints); | |
| 74 | } else if (task.status === 'Done') {
| |
| 75 | donePoints += Number(task.estimatedPoints); | |
| 76 | } | |
| 77 | } | |
| 78 | } | |
| 79 | console.log(`ToDo: ${toDoPoints}pts`);
| |
| 80 | console.log(`In Progress: ${inProgress}pts`);
| |
| 81 | console.log(`Code Review: ${codeReview}pts`);
| |
| 82 | console.log(`Done Points: ${donePoints}pts`);
| |
| 83 | ||
| 84 | if (donePoints >= toDoPoints + inProgress + codeReview) {
| |
| 85 | console.log(`Sprint was successful!`); | |
| 86 | } else {
| |
| 87 | console.log(`Sprint was unsuccessful...`) | |
| 88 | } | |
| 89 | } | |
| 90 | ||
| 91 | sprintReview( [ | |
| 92 | '5', | |
| 93 | 'Kiril:BOP-1209:Fix Minor Bug:ToDo:3', | |
| 94 | 'Mariya:BOP-1210:Fix Major Bug:In Progress:3', | |
| 95 | 'Peter:BOP-1211:POC:Code Review:5', | |
| 96 | 'Georgi:BOP-1212:Investigation Task:Done:2', | |
| 97 | 'Mariya:BOP-1213:New Account Page:In Progress:13', | |
| 98 | 'Add New:Kiril:BOP-1217:Add Info Page:In Progress:5', | |
| 99 | 'Change Status:Peter:BOP-1290:ToDo', | |
| 100 | 'Remove Task:Mariya:1', | |
| 101 | 'Remove Task:Joro:1', | |
| 102 | ] | |
| 103 | ||
| 104 | ||
| 105 | ) |