Repository navigation
London | 26-ITP-Sep | Bartosz Kawiak | Sprint 3 | Todo list - #1559
bartoszkawiak wants to merge 2 commits into
Conversation
|
The CYF AI reviewer checked this PR did not find any obvious problems. Please wait for a volunteer to also have a look and offer their own feedback. |
hackertainment
left a comment
There was a problem hiding this comment.
There are code changes related to tidy up code, which make the PR a bit hard to read and it took me quite a while to figure out which lines are actually related to the new logic. This program runs correctly. Just need to add the missing test cases and answer a question. Thank you.
| export function deleteCompleted(todoList) { | ||
| const remainingTodos = todoList.filter((todo) => !todo.completed); | ||
| todoList.splice(0, todoList.length, ...remainingTodos); | ||
| } |
There was a problem hiding this comment.
While this is correct, just wondering whether there is any reasons or advantages for choosing this approach over other implementations? Please explain a bit your design considerations. Thank you very much.
There was a problem hiding this comment.
I chose filter() because it makes it easy to keep only incomplete tasks without manually looping through the array. I then used splice() to update the original array, keeping it consistent with the other functions in todos.mjs.
There was a problem hiding this comment.
How about deleting tasks from a list with all tasks incomplete and from an empty list? Please add those test cases as well. Thank you.
There was a problem hiding this comment.
Thank you, I added both missing test cases and all the test passed.
Learners, PR Template
Self checklist
Task code
CYF-1097
Changelist
I added a Delete all completed tasks button, tested it in Jest and made sure it works in a browser.