Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(entry) {
- let data = entry
- .shift()
- .split(/[,\s]+/g)
- .sort((a,b)=>a.localeCompare(b));
- let healEx = /[^\d+\-*/\.]/g;
- let numEx = /([+-]?[0-9]+\.?[0-9]*)/g;
- let signEx = /[\/\*]/g;
- for (let line of data) {
- line = line.trim();
- let health = 0;
- let base = 0;
- while((match = healEx.exec(line)) !== null){
- health += match[0].charCodeAt();
- }
- while((match = numEx.exec(line)) !== null){
- base+=Number(match[0]);
- }
- while((match = signEx.exec(line)) !== null){
- if(match[0] === '/'){
- base/=2;
- }else{
- base*=2;
- }
- }
- console.log(`${line} - ${health} health, ${base.toFixed(2)} damage`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement