1
0
This commit is contained in:
Jason Williams 2019-08-11 12:56:43 -06:00
parent 6fe77562a9
commit 63e639fab3
3 changed files with 35 additions and 15 deletions

View File

@ -21,7 +21,7 @@ yargs.command({
type: 'string' type: 'string'
} }
}, },
handler: function(argv) { handler(argv) {
notes.addNote(argv.title, argv.body); notes.addNote(argv.title, argv.body);
} }
}); });
@ -37,7 +37,7 @@ yargs.command({
type: 'string' type: 'string'
} }
}, },
handler: function(argv) { handler(argv) {
notes.removeNote(argv.title); notes.removeNote(argv.title);
} }
}); });
@ -46,7 +46,7 @@ yargs.command({
yargs.command({ yargs.command({
command: 'list', command: 'list',
describe: 'List notes', describe: 'List notes',
handler: function() { handler() {
console.log('Listing out all notes'); console.log('Listing out all notes');
} }
}); });
@ -55,7 +55,7 @@ yargs.command({
yargs.command({ yargs.command({
command: 'read', command: 'read',
describe: 'Read a note', describe: 'Read a note',
handler: function() { handler() {
console.log('Reading a note'); console.log('Reading a note');
} }
}); });

View File

@ -1,15 +1,13 @@
const fs = require('fs'); const fs = require('fs');
const chalk = require('chalk'); const chalk = require('chalk');
const getNotes = function() { const getNotes = () => {
return 'Your notes...' return 'Your notes...'
} }
const addNote = function(title, body) { const addNote = (title, body) => {
const notes = loadNotes(); const notes = loadNotes();
const duplicateNotes = notes.filter(function(note) { const duplicateNotes = notes.filter((note) => note.title === title);
return note.title === title;
});
if (duplicateNotes.length === 0) { if (duplicateNotes.length === 0) {
notes.push({ notes.push({
@ -24,11 +22,9 @@ const addNote = function(title, body) {
} }
} }
const removeNote = function(title) { const removeNote = (title) => {
const notes = loadNotes(); const notes = loadNotes();
const notesToKeep = notes.filter(function(note) { const notesToKeep = notes.filter((note) => note.title !== title);
return note.title !== title;
});
if (notes.length > notesToKeep.length) { if (notes.length > notesToKeep.length) {
console.log(chalk.bgGreen.bold('Note removed!')); console.log(chalk.bgGreen.bold('Note removed!'));
@ -38,12 +34,12 @@ const removeNote = function(title) {
} }
} }
const saveNotes = function(notes) { const saveNotes = (notes) => {
const dataJSON = JSON.stringify(notes); const dataJSON = JSON.stringify(notes);
fs.writeFileSync('notes.json', dataJSON); fs.writeFileSync('notes.json', dataJSON);
} }
const loadNotes = function() { const loadNotes = () => {
try { try {
const dataBuffer = fs.readFileSync('notes.json'); const dataBuffer = fs.readFileSync('notes.json');
const dataJSON = dataBuffer.toString(); const dataJSON = dataBuffer.toString();

View File

@ -0,0 +1,24 @@
//
// Goal: Create method to get incomplete tasks
//
// 1. Define getTasksToDo method
// 2. Use filter to to return just the incompleted tasks (arrow function)
// 3. Test your work by running the script
const tasks = {
tasks: [{
text: 'Grocery shopping',
completed: true
},{
text: 'Clean yard',
completed: false
}, {
text: 'Film course',
completed: false
}],
getTasksToDo() {
return this.tasks.filter((task) => task.completed === false);
}
}
console.log(tasks.getTasksToDo())