From 6df620b854e07939808d76dc8c82f5c8cb6b4172 Mon Sep 17 00:00:00 2001 From: VikLchv Date: Sat, 20 Jun 2026 18:00:29 +0200 Subject: [PATCH] Fix search to match notes containing the term, not just exact matches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit search is meant to return every note that contains the term, but matches() in lib/store.js compared with ===, so "milk" only matched a note whose text was exactly "milk" — missing "buy milk" and "milk the almonds". Switched the predicate to String.includes, which is what the two failing tests expect. All three tests now pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/store.js | 2 +- notes.md | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 notes.md diff --git a/lib/store.js b/lib/store.js index 1d9215f..7ceefa0 100644 --- a/lib/store.js +++ b/lib/store.js @@ -38,7 +38,7 @@ function remove(id) { // Returns the notes that match `term`. function matches(notes, term) { - return notes.filter((note) => note.text === term); + return notes.filter((note) => note.text.includes(term)); } function search(term) { diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..f81c5f1 --- /dev/null +++ b/notes.md @@ -0,0 +1,19 @@ +# Lesson 2 — commit message comparison + +## My quick version (what I'd dash off) +fix search + +## Claude's version (the actual commit message) +Fix search to match notes containing the term, not just exact matches + +`search` is meant to return every note that *contains* the term, but `matches` +in lib/store.js compared with `===`, so "milk" only matched a note whose text +was exactly "milk" — missing "buy milk" and "milk the almonds". Switched the +predicate to `String.includes`, which is what the two failing tests expect. +All three tests pass. + +## Comparison +The quick version ("fix search") says nothing about what was wrong or why the +change is correct. The fuller message explains the actual bug (exact-equality +vs. substring), names the function, and ties the fix to the tests — so a future +reader understands the *why*, not just that something changed.