Beast Boost takes IVs/EVs into account when deciding which stat to raise. So taking Pheromosa for example, if she has perfect 31 IV in Attack, but 0 in Speed, her Attack stat will be higher than her Speed, and the Attack will get boosted instead.
Here's my code. There's probably a better way to...