Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let countassignee= Number(input.shift());
- let Allassignees={};// associative array
- for (let i = 0; i < countassignee; i++) {
- const[assignee,taskId,title,status,estimatedPoints1]=(input.shift()).split(':');
- let estimatedPoints=Number(estimatedPoints1);
- if(Allassignees[assignee]){
- Allassignees[assignee].alltasks.push({taskId,title,status,estimatedPoints});
- }
- else{
- Allassignees[assignee]={alltasks:[{taskId,title,status,estimatedPoints}]};
- }
- }
- // let Cmd= input.shift();
- for (const currentcmd of input) {
- ArrCmd= (currentcmd).split(':');
- let commandCmd=ArrCmd[0];
- let assignee= ArrCmd[1];
- let taskid=ArrCmd[2];
- switch (commandCmd) {
- case 'Add New':
- let title=ArrCmd[3];
- let status=ArrCmd[4];
- let estimatedPoints=Number(ArrCmd[5]);
- if(!Allassignees[assignee]){
- console.log(`Assignee ${assignee} does not exist on the board!`)
- }
- else{
- Allassignees[assignee].alltasks.push({taskid,title,status,estimatedPoints:estimatedPoints});
- }
- break;
- case 'Change Status':
- let newstatus=ArrCmd[3];
- if(Allassignees[assignee]){
- let currenttask= Allassignees[assignee].alltasks.find(t=> t.taskId==taskid);
- if(currenttask== null){
- console.log(`Task with ID ${taskid} does not exist for ${assignee}!`)
- }
- else{
- currenttask.status = newstatus;
- }
- }
- else{
- console.log(`Assignee ${assignee} does not exist on the board!`)
- }
- break;
- case 'Remove Task':
- let index=Number(taskid);
- if(!Allassignees[assignee]){
- console.log(`Assignee ${assignee} does not exist on the board!`)
- }
- else{
- let counttasks=Allassignees[assignee].alltasks.length;
- if(index <0 || index >=counttasks){
- console.log(`Index is out of range!`);
- }
- else{
- Allassignees[assignee].alltasks.splice(index,1);
- }
- }
- break;
- }
- }
- let FinalTasks={};
- FinalTasks['ToDo']= 0;
- FinalTasks['In Progress']= 0;
- FinalTasks['Code Review']= 0;
- FinalTasks['Done Points']= 0;
- for (const assignee in Allassignees) {
- for (const task of Allassignees[assignee].alltasks) {
- if(task.status=='ToDo'){
- FinalTasks['ToDo'] += task.estimatedPoints;
- }
- else if(task.status=='In Progress'){
- FinalTasks['In Progress'] += task.estimatedPoints;
- }
- else if(task.status=='Code Review'){
- FinalTasks['Code Review'] += task.estimatedPoints;
- }
- else if(task.status=='Done'){
- FinalTasks['Done Points'] +=task.estimatedPoints;
- }
- }
- }
- let countDone=0;
- let countothers=0;
- let AllEntries=Object.entries(FinalTasks);
- for (const key of AllEntries) {
- console.log(`${key[0]}: ${key[1]}pts`);
- switch(key[0]){
- case 'ToDo':
- countothers += Number(key[1]);
- break;
- case 'In Progress':
- countothers += Number(key[1]);
- break;
- case 'Code Review':
- countothers += Number(key[1]);
- break;
- case 'Done Points':
- countDone += Number(key[1]);
- break;
- }
- }
- if(countDone >= countothers){
- console.log(`Sprint was successful!`);
- }
- else{
- console.log(`Sprint was unsuccessful...`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement