From c8433c98cb112e4cabd5e6eee347efa68d81af0b Mon Sep 17 00:00:00 2001 From: Pavuk Date: Thu, 14 Oct 2021 20:25:35 +0500 Subject: [PATCH 1/3] Update index.js --- index.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8635050..ae0a55a 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,71 @@ -const {getAllFilePathsWithExtension, readFile} = require('./fileSystem'); -const {readLine} = require('./console'); - +const { getAllFilePathsWithExtension, readFile } = require('./fileSystem'); +const { readLine } = require('./console'); + const files = getFiles(); +const lines = parseLines(); +function parseLines() { + let parsedFiles = []; + let lines = []; + for (let i = 0; i < files.length; i++) { + parsedFiles.push(files[i].split("\r\n")); + lines = lines.concat(parsedFiles[i]); + } + return lines; +} + console.log('Please, write your command!'); readLine(processCommand); - + function getFiles() { const filePaths = getAllFilePathsWithExtension(process.cwd(), 'js'); return filePaths.map(path => readFile(path)); } - + function processCommand(command) { - switch (command) { + let commands = command.split(" "); + switch (commands[0]) { case 'exit': process.exit(0); break; + case 'show': + console.log(showTodo()); + break; + case 'important': + console.log(showExclamation()); + break; + case 'user': + console.log(showUserNames(words[1])); + break; default: console.log('wrong command'); break; } } +function showExclamation() { + let importantLines = []; + for (let line of lines) + if (line.includes("!") && line.includes("// TODO")) + importantLines.push(line.slice(line.indexOf("// TODO"))); + return importantLines; +} + + +function showUserNames(username) { + username.toLowerCase(); + let namedLines = []; + for (let line of lines) + if (line.toLowerCase().includes(username) && line.includes("// TODO")) + namedLines.push(line.slice(line.indexOf("// TODO")).split(';')[2].replace(' ', '')); + return namedLines; +} + +function showTodo() { + let toDoLines = []; + for (let line of lines) + if (line.includes("// TODO")) + toDoLines.push(line.slice(line.indexOf("// TODO"))); + return toDoLines; +} // TODO you can do it! From e38b508534447e3380da22a116a739a9c2cf8bb2 Mon Sep 17 00:00:00 2001 From: Pavuk Date: Thu, 14 Oct 2021 21:39:47 +0500 Subject: [PATCH 2/3] Update index.js --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ae0a55a..3041490 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,6 @@ function processCommand(command) { switch (commands[0]) { case 'exit': process.exit(0); - break; case 'show': console.log(showTodo()); break; @@ -35,7 +34,7 @@ function processCommand(command) { console.log(showExclamation()); break; case 'user': - console.log(showUserNames(words[1])); + console.log(showUserNames(commands[1])); break; default: console.log('wrong command'); @@ -53,7 +52,7 @@ function showExclamation() { function showUserNames(username) { - username.toLowerCase(); + username = username.toLowerCase(); let namedLines = []; for (let line of lines) if (line.toLowerCase().includes(username) && line.includes("// TODO")) From b1eea98bf26868a2ec76e864953c32f9c243c17d Mon Sep 17 00:00:00 2001 From: Pavuk Date: Thu, 14 Oct 2021 23:53:47 +0500 Subject: [PATCH 3/3] Update index.js --- index.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 3041490..ade282c 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,9 @@ const { getAllFilePathsWithExtension, readFile } = require('./fileSystem'); const { readLine } = require('./console'); const files = getFiles(); -const lines = parseLines(); +const lines = parseLl(); -function parseLines() { +function parseLl() { let parsedFiles = []; let lines = []; for (let i = 0; i < files.length; i++) { @@ -43,28 +43,28 @@ function processCommand(command) { } function showExclamation() { - let importantLines = []; - for (let line of lines) - if (line.includes("!") && line.includes("// TODO")) - importantLines.push(line.slice(line.indexOf("// TODO"))); - return importantLines; + let importantLl = []; + for (let l of lines) + if (l.includes("!") && l.includes("// TODO") && !(l.includes("\"// TODO\""))) + importantLl.push(l.slice(l.indexOf("// TODO"))); + return importantLl; } -function showUserNames(username) { - username = username.toLowerCase(); - let namedLines = []; - for (let line of lines) - if (line.toLowerCase().includes(username) && line.includes("// TODO")) - namedLines.push(line.slice(line.indexOf("// TODO")).split(';')[2].replace(' ', '')); - return namedLines; +function showUserNames(name) { + name = name.toLowerCase(); + let namedLl = []; + for (let l of lines) + if (l.toLowerCase().includes(name) && l.includes("// TODO") && !(l.includes("\"// TODO\""))) + namedLl.push(l.slice(l.indexOf("// TODO")).split(';')[2].replace(' ', '')); + return namedLl; } function showTodo() { - let toDoLines = []; - for (let line of lines) - if (line.includes("// TODO")) - toDoLines.push(line.slice(line.indexOf("// TODO"))); - return toDoLines; + let todoLl = []; + for (let l of lines) + if (l.includes("// TODO") && !(l.includes("\"// TODO\""))) + todoLl.push(l.slice(l.indexOf("// TODO"))); + return todoLl; } // TODO you can do it!