Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const data = args
- .shift()
- .split(/[,\s]+/g)
- .sort((a, b) => a.localeCompare(b));
- data.forEach((str) => {
- let damage = 0;
- const healthR = str.trim().match(/[^\d+\-*/\.]/g);
- const health = healthR.reduce((acc, currV) => acc + currV.charCodeAt(), 0);
- const damageR = str.trim().match(/([+-]?[0-9]+\.?[0-9]*)/g);
- if (damageR !== null) {
- damage = damageR !== null && damageR.map(Number).reduce((acc, currV) => acc + currV, 0);
- }
- const mathSymbols = str.trim().match(/[\/\*]/g);
- if (mathSymbols !== null) {
- mathSymbols.forEach((symb) => {
- if (symb === '/') {
- damage /= 2;
- } else {
- damage *= 2;
- }
- });
- }
- console.log(`${str} - ${health} health, ${damage.toFixed(2)} damage`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement