DEV Community

Razee Jafri
Razee Jafri

Posted on

From Complex Law to Simple Code: The Logic Behind a Financial Calculator

As developers, we often get the challenge of translating complex, real-world rules into simple, functional code. I recently faced this while working on a tool for expatriates in the UAE.

The problem: The UAE Labour Law has a multi-tiered formula for calculating an employee's end-of-service gratuity. The logic depends on variables like basic salary, years of service, and contract type (Limited vs. Unlimited).

The task was to build a simple interface that could handle these conditional rules accurately. I used JavaScript to create a function that:

Takes basicSalary, serviceYears, and contractType as inputs.

First, checks if serviceYears is >= 1.

Then, applies a tiered calculation: 21 days/year for the first 5 years, and 30 days/year thereafter.

Finally, it would apply specific reduction modifiers based on the contract type if the reason for leaving is 'resignation'.

The result is a clean, single-purpose tool that solves a major pain point for its users. It’s a great example of how a little bit of code can bring a lot of clarity to a complex situation.

You can see the final product in action here:

Top comments (0)