From 0db259802c2a2e7723f432f1dd61fcd01873a4f8 Mon Sep 17 00:00:00 2001 From: UralGuru <71888215+UralGuru@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:41:23 +0500 Subject: [PATCH] Update index.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1-5 задания) --- index.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/index.js b/index.js index 8635050..bf5d033 100644 --- a/index.js +++ b/index.js @@ -12,14 +12,93 @@ function getFiles() { } function processCommand(command) { + let commands = command.split(" "); + switch (command) { case 'exit': process.exit(0); break; + + + case 'show': + console.log(toShow()); + break; + + case 'important': + console.log(showImportant()); + break; + + case 'user': + console.log(showByUser(splitedCommand[1])); + break; + + case 'sort': + switch (commands[1]){ + case 'importance': + console.log(sortImp()); + break; + case 'user': + console.log(sortUser()); + break; + case 'date': + console.log(sortDate()); + break; + } + break; + default: console.log('wrong command'); break; } } +//2. show : показать все todo +function toShow() { + let lines = []; + for (let file of files) + lines.push(...file.split('\r\n')); + lines = lines.flat(Infinity); + const matches = []; + for (let line of lines) { + let search = line.indexOf(`// TODO`); + if (search != -1) + matches.push(line.substring(search)); + } + return matches; +} + +//3. important : показывать только todo, в которых есть восклицательный знак +function showImportant() { + let allTasks = toShow(); + let importantTasks = [] + for (let task of allTasks){ + if (task.includes('!')){ + importantTasks.push(task); + } + } + return importantTasks; +} + +//4. user {username} : показывать только комментарии от указанного пользователя +function showByUser(name){ + return toShow().filter(line => line.toLowerCase().includes(name.toLowerCase())) +} + +//5. sort {importance | user | date} : выводит отсортированные todo +// +function sortImp() { + let allTODO = toShow(); + return allTODO.sort(compareImp); +} + +function sortUser() { + let newAllTODO = toShow().sort().sort(compareUser); + return newAllTODO; +} + +function sortDate() { + let allTODO = toShow(); + return allTODO.sort(compareDate); +} // TODO you can do it! +//123\Desktop\Intensive\2-todo-statistic-master\2-todo-statistic-master\index.js