Last active
August 29, 2015 13:57
-
-
Save libo1106/9734344 to your computer and use it in GitHub Desktop.
BattleCamp平均值计算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bc($doms){ | |
var result = { | |
pr:0, | |
hp:0, | |
attack:0, | |
recovery:0, | |
feed:0 | |
} | |
var length = 0; | |
$doms.each(function(){ | |
var monsterID = getID($(this).find('.id').html()); | |
if(monsterID.indexOf('_') === -1){ | |
length++; | |
result.hp += getVal($(this).find('li').eq(5).html()); | |
result.attack += getVal($(this).find('li').eq(6).html()); | |
result.recovery += getVal($(this).find('li').eq(7).html()); | |
result.feed += getVal($(this).find('li').eq(8).html()); | |
} | |
}); | |
// ID名 | |
function getID(str){ | |
return str.replace(/<span>[\w ]{0,}<\/span>/,''); | |
} | |
// 数值 | |
function getVal(str){ | |
return parseInt(str.replace(/<span>[\w ]{0,}<\/span>/,'')); | |
} | |
return { | |
hp: Math.round(result.hp/length), | |
attack: Math.round(result.attack/length), | |
recovery: Math.round(result.recovery/length), | |
feed: Math.round(result.feed/length), | |
pr: Math.round(((result.hp/length)/5 + (result.attack/length) + (result.recovery/length)) / 100 ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment