Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let pattern = /[^0-9\+\-\*\/\.]/;
- let pattern2 = /[0-9\+\-\*\/\.]/;
- let workNames = input.split(/[\,][\s*]/);
- let arr = [];
- workNames = workNames.map(el => el.split(''));
- for (let el of workNames) {
- let filteredName = el.filter(str => str.match(pattern));
- let arithSymbols = el.filter(str => str.match(pattern2));
- let sum = arithSymbols.filter(el2 => el2.match(/^[+-]?\d+(\.\d+)?$/)).reduce((acc, el3) => acc + Number(el3), 0);
- sum = arithSymbols.filter(el2 => el2.match(/[*\/]/)).reduce((acc, el3) => el3.match(/[*]/) ? acc * 2 : acc / 2, sum);
- let totalHealth = filteredName.reduce((acc, el2) => acc + el2.charCodeAt(), 0);
- arr.push([el.join(''), { health: totalHealth, damage: sum.toFixed(2) }]);
- }
- arr.sort((a, b) => a[0].localeCompare(b[0]));
- // console.log(arr);
- for (let el of arr) {
- console.log(`${el[0]} - ${el[1]['health']} health, ${el[1]['damage']} damage`);
- }
- }
- solve(
- // 'M3ph1st0**, Azazel'
- 'M3ph-0.5s-0.5t0.0**'
- );
Add Comment
Please, Sign In to add comment