dunyto

Untitled

Mar 23rd, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function netherRealms(arr) {
  2.     let demons = {};
  3.     for (let line of arr) {
  4.         demons[line] = [];
  5.        
  6.         let hRegex = /[^0-9.+*/-]/g;
  7.         let dRegex = /[+-]{0,1}\d+[.\d+]{0,}/g;
  8.  
  9.         let healthChars = (line.match(hRegex) || []).join("");
  10.         let damageChars = line.match(dRegex);
  11.        
  12.         if (healthChars) {
  13.             let health = 0;
  14.             for (let ch = 0; ch < healthChars.length; ch ++) {
  15.                 let cCode = Number(healthChars.charCodeAt(ch));
  16.                 health += cCode;
  17.             }
  18.             demons[line].push(health);
  19.         } else {
  20.             demons[line].push(0.00);
  21.         }
  22.        
  23.        
  24.         if (damageChars) {
  25.             let damage = 0;
  26.             for (let d of damageChars) {
  27.                 damage += Number(d);
  28.             }
  29.             let altering = line.match(/[*/]/g);
  30.             if (altering) {
  31.                 for (let a of altering) {
  32.                     if (a === "*") {
  33.                         damage *= 2;
  34.                     } else if (a === "/") {
  35.                         damage /= 2;
  36.                     }
  37.                 }
  38.             }
  39.             demons[line].push(damage);
  40.         } else {
  41.             demons[line].push(0.00);
  42.         }
  43.        
  44.     }
  45.  
  46.     let results = Object.entries(demons);
  47.     results.sort();
  48.  
  49.     for (let demon of results) {
  50.         console.log(`${demon[0]} - ${demon[1][0].toFixed(2)} health, ${demon[1][1].toFixed(2)} damage`);
  51.     }
  52. }
  53. netherRealms(['M3ph-0.5s-0.5t0.0**']);
  54. netherRealms(['M3ph1st0**', 'Azazel']);
  55. netherRealms(['Gos/ho']);
Add Comment
Please, Sign In to add comment