Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function netherRealms(arr) {
- let demons = {};
- for (let line of arr) {
- demons[line] = [];
- let hRegex = /[^0-9.+*/-]/g;
- let dRegex = /[+-]{0,1}\d+[.\d+]{0,}/g;
- let healthChars = (line.match(hRegex) || []).join("");
- let damageChars = line.match(dRegex);
- if (healthChars) {
- let health = 0;
- for (let ch = 0; ch < healthChars.length; ch ++) {
- let cCode = Number(healthChars.charCodeAt(ch));
- health += cCode;
- }
- demons[line].push(health);
- } else {
- demons[line].push(0.00);
- }
- if (damageChars) {
- let damage = 0;
- for (let d of damageChars) {
- damage += Number(d);
- }
- let altering = line.match(/[*/]/g);
- if (altering) {
- for (let a of altering) {
- if (a === "*") {
- damage *= 2;
- } else if (a === "/") {
- damage /= 2;
- }
- }
- }
- demons[line].push(damage);
- } else {
- demons[line].push(0.00);
- }
- }
- let results = Object.entries(demons);
- results.sort();
- for (let demon of results) {
- console.log(`${demon[0]} - ${demon[1][0].toFixed(2)} health, ${demon[1][1].toFixed(2)} damage`);
- }
- }
- netherRealms(['M3ph-0.5s-0.5t0.0**']);
- netherRealms(['M3ph1st0**', 'Azazel']);
- netherRealms(['Gos/ho']);
Add Comment
Please, Sign In to add comment