Custom Attack Damage

So here's what I want the formula based around:

Subtract target defense from two times enemy attack. If difference is less than 1, damage is 1, else the damage is the difference.

Example 1:

Player ATK: 10
Enemy DMG: 6

20 - 6 = 14

14 > 1

DMG is 14

Example 2:

Enemy ATK: 10
Player DEF: 30

20 - 30 = -10

-10 < 1

DMG = 1

Can someone help me with this?
JavaScript:
Math.max(a.atk*2 - b.def, 1);

I'd advise giving this page a read if you're struggling with the damage formulas.

Original thread: https://forums.rpgmakerweb.com/threads/custom-attack-damage.118309/