You've been asked to refactor the function deterministicPartitionKey
in dpk.js
to make it easier to read and understand without changing its functionality. For this task, you should:
- Write unit tests to cover the existing functionality and ensure that your refactor doesn't break it. We typically use
jest
, but if you have another library you prefer, feel free to use it. - Refactor the function to be as "clean" and "readable" as possible. There are many valid ways to define those words - use your own personal definitions, but be prepared to defend them. Note that we do like to use the latest JS language features when applicable.
- Write up a brief (~1 paragraph) explanation of why you made the choices you did and why specifically your version is more "readable" than the original.
You will be graded on the exhaustiveness and quality of your unit tests, the depth of your refactor, and the level of insight into your thought process provided by the written explanation.
The original code honestly looks good to me and allowed me to write tests for each scenario. I modified it to change the flow of the conditions.
Added more detailed validations to the unit test and also added 4 additional tests to account for all different scenarios. In regards to function refactoring, I moved, set the initial return value at the beginning and modified it based on the scenarios. Also moved some instructions closer to where you actually need it