Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Заварин, Букина ФТ-201 #140

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 79 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,92 @@ function getFiles() {
}

function processCommand(command) {
switch (command) {
let command_name = command.split(' ')[0];
let args = command.split(' ').slice(1);
switch (command_name) {
case 'exit':
process.exit(0);
break;
case 'show':
show();
break;
case 'important':
important();
break;
case 'sort':
sort(args[0]);
break;
case 'user':
user(args[0]);
break;
default:
console.log('wrong command');
break;
}
}

function allTodos() {
let list = getFiles();
return list.map(x => x.match(/\/\/ TODO.*/g)).reduce(function (a, b) {
return a.concat(b);
}, [])
}


function show() {
let list = getFiles();
list.map(x => x.match(/\/\/ TODO.*/g)).reduce(function (a, b) {
return a.concat(b);
}, []).forEach(x => console.log(x));
}

function important() {
let list = getFiles();
list.map(x => x.match(/\/\/ TODO.*!.*/g)).reduce(function (a, b) {
return b === null ? a : a.concat(b);
}, []).forEach(x => console.log(x));
}


function sort(arg) {
let all = allTodos();
switch (arg) {
case 'importance':
{
let list = getFiles();
important();
list.map(x => x.match(/\/\/ TODO[^!\r\n]+\r/g)).reduce(function (a, b) {
return b === null ? a : a.concat(b);
}, []).sort((a, b) => a.split('!').length < b.split('!').length).forEach(x => console.log(x));
break;
}
case 'date':
{
let withDate = all.filter((el) => el.split(";").length === 3);
let withoutDate = all.filter((el) => el.split(";").length !== 3);
withDate
.sort((a, b) => {
a = new Date(a.split(";")[1]);
b = new Date(b.split(";")[1]);
return a > b ? -1 : a < b ? 1 : 0;
})
.concat(withoutDate).forEach(x => console.log(x));
break;
}
case 'user':
{
return all
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.sort((a, b) => b.split(";").length - a.split(";").length).forEach(x => console.log(x));
}
}
}

function user(username) {
files.map(x => x.match(new RegExp(`\/\/ TODO ${username};.*;.*`, 'gi')))
.reduce((a, b) => b === null ? a : a.concat(b), [])
.forEach(x => console.log(x));
}


// TODO you can do it!