Update compare.php

Refactor compare_series function