Build a stamp duty calculator for various types of buyers I had a task where I had to build a stamp duty calculator, which calculates the tax or stamp duty first-time buyers(ftb) returning buyers (rtb), and second-home buyers (shb) had to pay when purchasing the home.
These were the tax bands, although I think some of the percentages may be slightly wrong.
First Time Buyers
0 to £300,000 - 0%
£300,001 to £925,000 - 5%
£925001 to £1,500,000 - 10%
£1,500,000 and above - 12%

Returning Buyers
0 to £125,000 - 0%
£125,001 to £250,000 - 2%
£250,001 to £925,000 - 5%
£925,001 to £1,500,000 - 10%
£1,500,000 and above - 12%

Second Home Buyers
0 to £125,000 - 3%
£125,001 to £250,000 - 5%
£250,001 to £925,000 - 8%
£925,001 to £1,500,000 - 13%
£1,500,000 and above - 15%

Here is my solution, I look forward to the feedback.
const stampDutyCalc = (price) =&gt; {
  let stampdutyObject = {
    ftb: 0,
    rtb: 0,
    shb: 0,
  };

  firstTimeBuyerCalc(price, stampdutyObject);
  returningBuyerCalc(price, stampdutyObject);
  secondHomeBuyerCalc(price, stampdutyObject);

  return stampdutyObject;
};

function firstTimeBuyerCalc(price, stampdutyObject) {
  if (price &lt;= 300000) {
    stampdutyObject.ftb += 0;
  } else if (price &gt; 300000 &amp;&amp; price &lt;= 925000) {
    stampdutyObject.ftb += price * 0.05;
  } else if (price &gt; 925000 &amp;&amp; price &lt;= 1500000) {
    stampdutyObject.ftb += (price - 925000) * 0.1 + (925000 - 300000) * 0.05;
  } else {
    stampdutyObject.ftb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 300000) * 0.05;
  }
}

function returningBuyerCalc(price, stampdutyObject) {
  if (price &lt;= 125000) {
    stampdutyObject.rtb += 0;
  } else if (price &gt; 125000 &amp;&amp; price &lt;= 250000) {
    stampdutyObject.rtb += price * 0.02;
  } else if (price &gt; 250000 &amp;&amp; price &lt;= 925000) {
    stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
  } else if (price &gt; 925000 &amp;&amp; price &lt;= 1500000) {
    stampdutyObject.rtb +=
      (price - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  } else {
    stampdutyObject.rtb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  }
}

function secondHomeBuyerCalc(price, stampdutyObject) {
  if (price &lt;= 125000) {
    stampdutyObject.shb = price * 0.03;
  } else if (price &gt; 125000 &amp;&amp; price &lt;= 250000) {
    stampdutyObject.shb += (price - 125000) * 0.05 + 125000 * 0.03;
  } else if (price &gt; 250000 &amp;&amp; price &lt;= 925000) {
    stampdutyObject.shb +=
      (price - 250000) * 0.08 + (250000 - 125000) * 0.05 + 125000 * 0.03;
  } else if (price &gt; 925000 &amp;&amp; price &lt;= 1500000) {
    stampdutyObject.shb +=
      (price - 925000) * 0.13 +
      (925000 - 250000) * 0.08 +
      (250000 - 125000) * 0.05 +
      125000 * 0.03;
  } else {
    stampdutyObject.shb +=
      (price - 1500000) * 0.15 +
      (1500000 - 925000) * 0.13 +
      (925000 - 250000) * 0.08 +
      (250000 - 125000) * 0.0 +
      125000 * 0.03;
  }
}

function returningBuyerCalc(price, stampdutyObject) {
  if (price &lt;= 125000) {
    stampdutyObject.rtb += 0;
  } else if (price &gt; 125000 &amp;&amp; price &lt;= 250000) {
    stampdutyObject.rtb += price * 0.02;
  } else if (price &gt; 250000 &amp;&amp; price &lt;= 925000) {
    stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
  } else if (price &gt; 925000 &amp;&amp; price &lt;= 1500000) {
    stampdutyObject.rtb +=
      (price - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  } else {
    stampdutyObject.rtb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  }
}
Hard coded
You have created yourself a future problem by hard coding the data in your code.  When dealing with taxes (or any business logic)  there is one certainty, and that is change.
With the data embedded in the code, making even a minor change will take some effort and will be very prone to error.
You need to create a data structure that allows you to make changes quickly and easily. You should only have to change a value once, in one location, not many times in many places.
Defining the data
The data is defined as an object, with only the data needed, if information can be deduced there is no need to include it.
The example has a helper function rate to reduce the overhead of typing in {level:10000, tax: 0.1} over and over
const rate = (level, tax) =&gt; ({level, tax});
const brackets = {
    firstTime: [
        rate(300000, 0),
        rate(925000, 0.05),
        rate(1500000, 0.1),
        rate(Infinity, 0.12),
    ],
    returning: [
        rate(125000, 0),
        rate(250000, 0.02),
        rate(925000, 0.05),
        rate(1500000, 0.1),
        rate(Infinity, 0.12),   
    ],
    second: [
        rate(125000, 0.03),
        rate(250000, 0.05),
        rate(925000, 0.08),
        rate(1500000, 0.13),
        rate(Infinity, 0.15),       
    ],
};

Applying logic
With the data organised, the code can then just deal with the logic of how the duty is calculated:
function calculateDuty(price, bracket) {
    var duty = 0;
    var prevLevel = 0
    for (const rate of bracket) {
        if (rate.level &lt;= price) {
            duty += (rate.level - prevLevel) * rate.tax;
            prevLevel = rate.level;
        } else {
            return duty + (price - prevLevel) * rate.tax;
        }
    }
}

And now you can get the duty for any bracket: calculateDuty(price, brackets.firstTime)
Rewrite
Thus the whole thing becomes:
const rate = (level, tax) =&gt; ({level, tax});
const brackets = {
    firstTime: [rate(300000, 0), rate(925000, 0.05), rate(1500000, 0.1), rate(Infinity, 0.12)],
    returning: [rate(125000, 0), rate(250000, 0.02), rate(925000, 0.05), rate(1500000, 0.1), rate(Infinity, 0.12)],
    second: [rate(125000, 0.03), rate(250000, 0.05), rate(925000, 0.08), rate(1500000, 0.13), rate(Infinity, 0.15)],
};
const stampDutyCalc = price =&gt; ({  
    ftb: calculateDuty(price, brackets.firstTime),
    rtb: calculateDuty(price, brackets.returning), 
    shb: calculateDuty(price, brackets.second), 
});

function calculateDuty(price, bracket) {
    var duty = 0, prevLevel = 0
    for (const rate of bracket) {
        if (rate.level &lt;= price) {
            duty += (rate.level - prevLevel) * rate.tax;
            prevLevel = rate.level;
        } else {
            return duty + (price - prevLevel) * rate.tax;
        }
    }
}