Reduced Number of Parameters from getCategories Helper Function #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
P1B: Starter Task: Refactoring PR
1. Issue
#57
src/controllers/helpers.js
It contains many helper functions for the controller. These can include functions to allow filtering, sorting, etc..
Edited the function header to change the parameters. Also changed the way the function was called in the code in the controllers file.
Function with many parameters (count = 4): getCategories
2. Refactoring
The function's large number of parameters made it hard to change or add onto which could make future additions harder to implement. With a more structured parameter head its now much easier to add/remove parameters based on what's needed.
Instead of multiple parameters, I simply made input be one array parameter that includes those parameters.
Now you can simply ommit elements of the array and it still works fine.
3. Validation
I ran the 'npm run test' after adding print statements to the parts of the code affected by my changes and checked if they both appeared and still gave the right amount of coverage (meaning it didn't break the code)