Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input){
- let regex = /,\s*/g;
- let collectionArrD = input.split(regex);
- // console.log(collectionArrD);
- let battleBookObj = {};
- let healthPattern = /[^0-9+\-*/\.]/g;
- let patternNums = /-?\d+(?:.\d+)?/g;
- for (let currentLine of collectionArrD) {
- // TO find Health of the DEM
- let name = currentLine;
- let matches = currentLine.match(healthPattern);
- let healtDEM = 0;
- if(matches!== null){
- for ( let x of matches) {
- healtDEM+= x.charCodeAt(0);
- }
- }
- // TO find damage of DEM
- let matchesNums = currentLine.match(patternNums);
- let tempSumNums = 0;
- if(matchesNums!== null){
- for (let x of matchesNums) {
- tempSumNums+= Number(x);
- }
- }
- if (tempSumNums !==0){
- for (let x of currentLine.split("")) {
- if ( x == "*"){
- tempSumNums= tempSumNums*2;
- } else if (x == "/"){
- tempSumNums = tempSumNums/2;
- }
- }
- } else{
- tempSumNums=0;
- }
- let damageDEM = tempSumNums;
- if(battleBookObj.hasOwnProperty(name)== false){
- battleBookObj[name] = { healtDEM, damageDEM};
- }
- }
- // console.log(battleBookObj);
- let sortedByName= Object.keys(battleBookObj).sort((a,b)=> a.localeCompare(b));
- for (let nameObj of sortedByName) {
- console.log(`${nameObj} - ${battleBookObj[nameObj].healtDEM} health, ${battleBookObj[nameObj].damageDEM.toFixed(2)} damage`);
- }
- }
- solve("M3ph-0.5s-0.5t0.0**");
- console.log(`###########`);
- solve("M3ph1st0**, Azazel");
- console.log(`###########`);
- solve("Gos/ho")
Add Comment
Please, Sign In to add comment