Video 22
This commit is contained in:
parent
6fe77562a9
commit
63e639fab3
@ -21,7 +21,7 @@ yargs.command({
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
handler: function(argv) {
|
||||
handler(argv) {
|
||||
notes.addNote(argv.title, argv.body);
|
||||
}
|
||||
});
|
||||
@ -37,7 +37,7 @@ yargs.command({
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
handler: function(argv) {
|
||||
handler(argv) {
|
||||
notes.removeNote(argv.title);
|
||||
}
|
||||
});
|
||||
@ -46,7 +46,7 @@ yargs.command({
|
||||
yargs.command({
|
||||
command: 'list',
|
||||
describe: 'List notes',
|
||||
handler: function() {
|
||||
handler() {
|
||||
console.log('Listing out all notes');
|
||||
}
|
||||
});
|
||||
@ -55,7 +55,7 @@ yargs.command({
|
||||
yargs.command({
|
||||
command: 'read',
|
||||
describe: 'Read a note',
|
||||
handler: function() {
|
||||
handler() {
|
||||
console.log('Reading a note');
|
||||
}
|
||||
});
|
||||
|
@ -1,15 +1,13 @@
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const getNotes = function() {
|
||||
const getNotes = () => {
|
||||
return 'Your notes...'
|
||||
}
|
||||
|
||||
const addNote = function(title, body) {
|
||||
const addNote = (title, body) => {
|
||||
const notes = loadNotes();
|
||||
const duplicateNotes = notes.filter(function(note) {
|
||||
return note.title === title;
|
||||
});
|
||||
const duplicateNotes = notes.filter((note) => note.title === title);
|
||||
|
||||
if (duplicateNotes.length === 0) {
|
||||
notes.push({
|
||||
@ -24,11 +22,9 @@ const addNote = function(title, body) {
|
||||
}
|
||||
}
|
||||
|
||||
const removeNote = function(title) {
|
||||
const removeNote = (title) => {
|
||||
const notes = loadNotes();
|
||||
const notesToKeep = notes.filter(function(note) {
|
||||
return note.title !== title;
|
||||
});
|
||||
const notesToKeep = notes.filter((note) => note.title !== title);
|
||||
|
||||
if (notes.length > notesToKeep.length) {
|
||||
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);
|
||||
fs.writeFileSync('notes.json', dataJSON);
|
||||
}
|
||||
|
||||
const loadNotes = function() {
|
||||
const loadNotes = () => {
|
||||
try {
|
||||
const dataBuffer = fs.readFileSync('notes.json');
|
||||
const dataJSON = dataBuffer.toString();
|
||||
|
24
playground/3-arrow-function.js
Normal file
24
playground/3-arrow-function.js
Normal 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())
|
Loading…
Reference in New Issue
Block a user