Skip to content

feat: implement recipe filtering and sorting using pure functions#2

Open
imran-s-creator wants to merge 1 commit intomainfrom
feature/filter-sort-recipes
Open

feat: implement recipe filtering and sorting using pure functions#2
imran-s-creator wants to merge 1 commit intomainfrom
feature/filter-sort-recipes

Conversation

@imran-s-creator
Copy link
Owner

Summary

This PR implements the Part 2 requirements for the Recipe App, introducing interactive filtering and sorting functionality. The implementation strictly follows Functional Programming principles, specifically focusing on pure functions and immutability.

Features Added

  • Filter Buttons: "Show All", "Easy", "Medium", "Hard", and "Quick Recipes" (< 30 min).
  • Sort Buttons: "Sort by Name (A-Z)", "Sort by Time (Fastest First)", and "Default Order".
  • Active State Indicators: Visual feedback on buttons to show currently applied filters/sorting.
  • Combined Logic: Ability to filter and sort simultaneously (e.g., Easy recipes sorted by Time).

Technical Implementation

  • Immutability: Used the spread operator [...recipes] before sorting to avoid mutating the original data.
  • Pure Functions: Created independent functions like filterByDifficulty and sortByTime that always return a new array.
  • Centralized State: Shared currentFilter and currentSort variables to keep the UI in sync.
  • Declarative Updates: Utilized a main updateDisplay() function to orchestrate the data flow (Filter -> Sort -> Render).

Testing Performed

  1. Verified that clicking "Easy" correctly reduces the visible list.
  2. Verified that "Sort by Time" arranges recipes from shortest to longest duration.
  3. Verified that the "Active" class toggles correctly between buttons.
  4. Checked console logs to ensure data flow is predictable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant