Last active
December 17, 2016 06:03
-
-
Save chadsten/d7bc43e2bcfade5bcbe406cfa1559545 to your computer and use it in GitHub Desktop.
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
<?php | |
function adjust_for_variance($price_array, $variance_threshold) { | |
$variance = calculate_variance($price_array); | |
if ($variance > $variance_threshold) { | |
sort($price_array); | |
array_pop($price_array); | |
$price_array = adjust_for_variance($price_array, $variance_threshold); | |
} else { | |
return $price_array; | |
} | |
} | |
function calculate_variance($price_array) { | |
if (is_array($price_array)) { | |
return round(((max($price_array) - min($price_array)) / (array_sum($price_array) / count($price_array)) * 100), 3); | |
} else { | |
return "<span class='nan'></span>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment