Skip to content

Instantly share code, notes, and snippets.

@ThienTranDuy
Last active April 20, 2020 03:28
Show Gist options
  • Save ThienTranDuy/ba118ba1e14d77e66378674eb88e95e6 to your computer and use it in GitHub Desktop.
Save ThienTranDuy/ba118ba1e14d77e66378674eb88e95e6 to your computer and use it in GitHub Desktop.
function plusMinus($arr) {
$arrLen = count($arr);
$posi = count(array_filter($arr, "countPosi"));
$nega = count(array_filter($arr, "countNega"));
$zero = count(array_filter($arr, "countZero"));
$ratioPosi = $posi / $arrLen;
$ratioNega = $nega / $arrLen;
$ratioZero = $zero / $arrLen;
echo abs(number_format($ratioPosi, 6, '.', '' )) ."\n";
echo abs(number_format($ratioNega, 6, '.', '' )) ."\n";
echo abs(number_format($ratioZero, 6, '.', '' )) ."\n";
}
function countPosi($val) {return $val > 0;}
function countNega($val) {return $val < 0;}
function countZero($val) {return $val === 0;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment