From 57d5f34ee530ccd290fe8b7281c2560f0b0183cd Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 21 Nov 2024 09:33:20 +0100 Subject: [PATCH] Better trim --- lab2/dictionary.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lab2/dictionary.cc b/lab2/dictionary.cc index feaf66d..7bfd397 100644 --- a/lab2/dictionary.cc +++ b/lab2/dictionary.cc @@ -83,14 +83,16 @@ void Dictionary::trim_suggestions(std::vector &suggestions, suggestions.erase(std::remove(suggestions.begin(), suggestions.end(), word), suggestions.end()); - // Example: Remove any suggestions that are too short - suggestions.erase( - std::remove_if(suggestions.begin(), suggestions.end(), - [](const std::string &s) { - return s.length() < - 3; // Remove words shorter than 3 characters - }), - suggestions.end()); + auto l = word.length(); + std::cout << "WTF" << l << std::endl; + + // Example: Remove any suggestions that are not within 1 string length + suggestions.erase(std::remove_if(suggestions.begin(), suggestions.end(), + [l](const std::string &s) { + return s.length() > (l + 1) || + s.length() < (l - 1); + }), + suggestions.end()); } int Dictionary::spit(path p) {