From a4bb78117f705737b0cbffcd5adc38e879fca727 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 5 Mar 2024 17:33:26 +0500 Subject: [PATCH 01/10] 123 --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 8635050..56e332a 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const {getAllFilePathsWithExtension, readFile} = require('./fileSystem'); const {readLine} = require('./console'); const files = getFiles(); +let todos = []; console.log('Please, write your command!'); readLine(processCommand); From d0e80cd0530b19bb01b1a4f254945b3cec5c2bcb Mon Sep 17 00:00:00 2001 From: Firchalka Date: Tue, 5 Mar 2024 17:40:33 +0500 Subject: [PATCH 02/10] show --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 56e332a..2682c08 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,11 @@ function processCommand(command) { case 'exit': process.exit(0); break; + case 'show': + for (let i = 0; i < todos.length; i++) { + console.log(todos[i]); + } + break; default: console.log('wrong command'); break; From aa636ce6e4927d69f897a6f802f0ea7270d3a484 Mon Sep 17 00:00:00 2001 From: Firchalka Date: Tue, 5 Mar 2024 17:46:58 +0500 Subject: [PATCH 03/10] important --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index 2682c08..0925cab 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,15 @@ function processCommand(command) { console.log(todos[i]); } break; + case 'important': + let currentToDo; + for (let i = 0; i < todos.length; i++) { + currentToDo = todos[i]; + if (currentToDo.includes('!')) { + console.log(currentToDo); + } + } + break; default: console.log('wrong command'); break; From ff19f579088b92eb113092961f462d9f33bf9892 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 5 Mar 2024 17:56:27 +0500 Subject: [PATCH 04/10] todos --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 56e332a..d82297e 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,13 @@ const {getAllFilePathsWithExtension, readFile} = require('./fileSystem'); const {readLine} = require('./console'); const files = getFiles(); + +let re = /\/\/ TODO .*/g; let todos = []; +for(let file of files) { + let c_todos = file.match(re); + todos = todos.concat(c_todos); +} console.log('Please, write your command!'); readLine(processCommand); From 08049b85cbaf030330f36baf428f9cf086835a31 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 5 Mar 2024 18:12:52 +0500 Subject: [PATCH 05/10] user c --- index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 1ff38c0..b7df37e 100644 --- a/index.js +++ b/index.js @@ -19,16 +19,16 @@ function getFiles() { } function processCommand(command) { - switch (command) { - case 'exit': + switch (true) { + case /exit$/g.test(command): process.exit(0); break; - case 'show': + case /show$/g.test(command): for (let i = 0; i < todos.length; i++) { console.log(todos[i]); } break; - case 'important': + case /important$/g.test(command): let currentToDo; for (let i = 0; i < todos.length; i++) { currentToDo = todos[i]; @@ -37,10 +37,19 @@ function processCommand(command) { } } break; + case /user .*$/g.test(command): + let userName = command.split(' ')[1].toLowerCase(); + let pattern = new RegExp(`\/\/ TODO .*${userName};`, 'g'); + for (let todo of todos) { + if (pattern.test(todo)) { + console.log(todo); + } + } + break; default: console.log('wrong command'); break; } } -// TODO you can do it! +// TODO you can do it! \ No newline at end of file From 6f4e175579e2d1d74e3e9ad19fad8945d7db3d25 Mon Sep 17 00:00:00 2001 From: Firchalka Date: Tue, 5 Mar 2024 18:17:26 +0500 Subject: [PATCH 06/10] important --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b7df37e..5e7f615 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const files = getFiles(); let re = /\/\/ TODO .*/g; let todos = []; -for(let file of files) { +for (let file of files) { let c_todos = file.match(re); todos = todos.concat(c_todos); } @@ -46,6 +46,8 @@ function processCommand(command) { } } break; + case /sort .*/g.test(command): + let argument = command.split(" ")[1]; default: console.log('wrong command'); break; From 3585df8934152d96dd044492b6eb641037ec994e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 5 Mar 2024 18:55:48 +0500 Subject: [PATCH 07/10] 123 --- index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/index.js b/index.js index 5e7f615..42f77af 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,8 @@ for (let file of files) { todos = todos.concat(c_todos); } +console.log(sortByUsers(todos)); + console.log('Please, write your command!'); readLine(processCommand); @@ -54,4 +56,27 @@ function processCommand(command) { } } +function sortByUsers(todosList) { + const extractNameRegex = /\/\/ TODO (?\w*);/; + const todoByName = []; + for (let todo of todosList) { + let match = todo.match(extractNameRegex); + if (match === null) { + todoByName.push([null, todo]); + continue; + } + todoByName.push([match.groups.name.toLowerCase(), todo]); + } + todoByName.sort(function(a, b) { + if (a === null || a[0] < b[0]) { + return -1; + } + if (b === null || a[0] > b[0]) { + return 1; + } + return 0; + }); + return todoByName.map(a => a[1]) +} + // TODO you can do it! \ No newline at end of file From fa4150cefaf834941950e9c732f71c972b57af93 Mon Sep 17 00:00:00 2001 From: Firchalka Date: Tue, 5 Mar 2024 18:56:51 +0500 Subject: [PATCH 08/10] important --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 42f77af..9a91018 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,21 @@ function processCommand(command) { break; case /sort .*/g.test(command): let argument = command.split(" ")[1]; + if (argument === 'importance') { + let important = new Map(); + let currentToDo; + let currentCountExclamationMarks; + for (let i = 0; i < todos.length; i++) { + currentToDo = todos[i]; + currentCountExclamationMarks = (currentToDo.match(/!/g) || []).length; + important.set(currentCountExclamationMarks, currentToDo); + } + const sortedTodos = [...important].sort().reverse() + for (let i = 0; i < sortedTodos.length; i++) { + console.log(sortedTodos[i][1]); + } + } + break default: console.log('wrong command'); break; From 13fb821af377334703fa0792e27ff0fa2725ab92 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 5 Mar 2024 19:14:27 +0500 Subject: [PATCH 09/10] date --- index.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9a91018..c666a1b 100644 --- a/index.js +++ b/index.js @@ -10,8 +10,6 @@ for (let file of files) { todos = todos.concat(c_todos); } -console.log(sortByUsers(todos)); - console.log('Please, write your command!'); readLine(processCommand); @@ -65,12 +63,34 @@ function processCommand(command) { } } break + case /date .*/g.test(command): + let after = Date.parse(command.split(' ')[1]); + for (let todo of getTodosAfterDate(todos, after)) { + console.log(todo); + } + break; default: console.log('wrong command'); break; } } +function getTodosAfterDate(todosList, dateAfter) { + const dateExtractor = /\/\/ TODO (\w*); (?[\d]+(-[\d]+)*)/; + let result = []; + for (let todo of todosList) { + let m = todo.match(dateExtractor); + if (m === null){ + continue; + } + let date = Date.parse(m.groups.date); + if (date > dateAfter) { + result.push(todo); + } + } + return result; +} + function sortByUsers(todosList) { const extractNameRegex = /\/\/ TODO (?\w*);/; const todoByName = []; From 903197dc3b008c8c3186b42d865ff8dbc8aa322d Mon Sep 17 00:00:00 2001 From: Firchalka Date: Tue, 5 Mar 2024 19:27:46 +0500 Subject: [PATCH 10/10] result --- index.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c666a1b..d3b66db 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,29 @@ function processCommand(command) { for (let i = 0; i < sortedTodos.length; i++) { console.log(sortedTodos[i][1]); } + } else if (argument === "user") { + console.log(sortByUsers(todos)) + } else if (argument === 'date') { + const regex = /\d{4}-\d{2}-\d{2}/; + let datesAndTodos = [] + let currentToDo; + for (let i = 0; i < todos.length; i++) { + currentToDo = todos[i]; + const match = currentToDo.match(regex); + if (match){ + const dateString = match[0]; + const dateObject = Date.parse(dateString); + datesAndTodos.push([dateObject,currentToDo]) + } + else{ + datesAndTodos.push([Date.parse('3000-01-01'),currentToDo]) + } + + } + datesAndTodos.sort((a,b) => a[0] - b[0]) + for (let todo of datesAndTodos){ + console.log(todo[1]); + } } break case /date .*/g.test(command): @@ -102,7 +125,7 @@ function sortByUsers(todosList) { } todoByName.push([match.groups.name.toLowerCase(), todo]); } - todoByName.sort(function(a, b) { + todoByName.sort(function (a, b) { if (a === null || a[0] < b[0]) { return -1; }