Skip to content

Conversation

@atchamwa
Copy link

P1B: Starter Task: Refactoring PR

You are not permitted to use generative AI services (e.g., ChatGPT) to compose the answers.
Any such use will be treated as a violation of academic integrity.

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)

inside function
called helper

less smells

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