Viewing a response to: @matthewdavid/removing-a-note-day-seven-of-the-complete-node-js-developer-course
Do you need this part? var note = {title} ? JS is dynamic so not sure you need the definition. If not you could reduce to this :) ``` var removeNote = (title) => { saveNotes(fetchNotes().filter((note) => note.title !== title) } ``` The bit you are fighting with should click in a minute... ``` var wantNote = (note) => note.title !== title; ``` Notice how similar the definition of removeNote is when written this way. That is because wantNote is just another function but in this case you have not assigned it to a variable, just passed it direct to filter. Filter is known as a high order function, in that it takes a function as an argument. You can pass functions around as you would say a string. They are just another bit of data. This is very common in JS and also many current languages. How filter works is this, it gets the list of notes and your tester function. It then walks through all the notes and tests if you want to keep it, if so it adds it to the results and if not it discards it. The results are all the notes that passed the test function you supplied. Done in C# as know the syntax better but similar enough you should understand :) There is a cleaner way but this should make it easy to see what is going on ``` public static IEnumerable<Note> Filter( this IEnumerable<Note> toFilter, Func<Note, bool> predicate) { var result = new List<Note>(); foreach (var note in toFilter) { if (predicate(note)) { result.Add(note); } } return result; } ``` So this gets an IEnumerable (list) of notes and a function from note to bool. Called predicate as that is the common term for something that takes a value and returns true/false because maths :) HTH Woz
author | woz.software |
---|---|
permlink | re-matthewdavid-removing-a-note-day-seven-of-the-complete-node-js-developer-course-20170912t064326670z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-12 06:43:30 |
last_update | 2017-09-12 06:43:30 |
depth | 1 |
children | 2 |
last_payout | 2017-09-19 06:43:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.038 HBD |
curator_payout_value | 0.013 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,753 |
author_reputation | 2,321,910,395,519 |
root_title | "Removing a Note: Day Seven of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,629,234 |
net_rshares | 18,863,291,227 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
matthewdavid | 0 | 18,863,291,227 | 100% |
Thank you. This helps! I appreciate that you took the time to explain it.
author | matthewdavid |
---|---|
permlink | re-wozsoftware-re-matthewdavid-removing-a-note-day-seven-of-the-complete-node-js-developer-course-20170913t042749915z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-13 04:27:54 |
last_update | 2017-09-13 04:27:54 |
depth | 2 |
children | 1 |
last_payout | 2017-09-20 04:27:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 74 |
author_reputation | 2,155,255,892,877 |
root_title | "Removing a Note: Day Seven of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,723,475 |
net_rshares | 6,514,013,641 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
woz.software | 0 | 6,514,013,641 | 100% |
More than happy to help. You are doing the right thing writing like this, it helps get things clear in your head. I found that with my roguelike series. Actually found bugs and fixed them while writing the articles explaining the code :)
author | woz.software |
---|---|
permlink | re-matthewdavid-re-wozsoftware-re-matthewdavid-removing-a-note-day-seven-of-the-complete-node-js-developer-course-20170913t095509874z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-13 09:55:09 |
last_update | 2017-09-13 09:55:09 |
depth | 3 |
children | 0 |
last_payout | 2017-09-20 09:55:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.038 HBD |
curator_payout_value | 0.012 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 237 |
author_reputation | 2,321,910,395,519 |
root_title | "Removing a Note: Day Seven of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,744,987 |
net_rshares | 18,567,009,166 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
matthewdavid | 0 | 18,567,009,166 | 100% |