DEV Community


Discussion on: Daily Challenge #43 - Boardgame Fight Resolver

ynndvn profile image
La blatte

How bout some G O L F


If I understood the problem correctly, the defender only wins if it is the "previous" element on the list. Hence, I just store a string with the initials in the correct order, check the initial index. If the defender is just before the attacker, it wins.

r=['Archers', 'Swordsmen', 'Pikemen', 'Cavalry'];
s='',r.forEach(e=>r.forEach(k=>s+=`${e} VS ${k}: ${f(e,k)}\n`)),s 

"Archers VS Archers: Archers
Archers VS Swordsmen: Archers
Archers VS Pikemen: Archers
Archers VS Cavalry: Cavalry
Swordsmen VS Archers: Archers
Swordsmen VS Swordsmen: Swordsmen
Swordsmen VS Pikemen: Swordsmen
Swordsmen VS Cavalry: Swordsmen
Pikemen VS Archers: Pikemen
Pikemen VS Swordsmen: Swordsmen
Pikemen VS Pikemen: Pikemen
Pikemen VS Cavalry: Pikemen
Cavalry VS Archers: Cavalry
Cavalry VS Swordsmen: Cavalry
Cavalry VS Pikemen: Pikemen
Cavalry VS Cavalry: Cavalry