Passed
Branch master (a9ed3d)
by Daniel
23:14 queued 31s
created

altbetterThanAverage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
There was a test in your class and you passed it. Congratulations!
4
But you're an ambitious person. You want to know if you're better than the average student in your class.
5
6
You receive an array with your peers' test scores. Now calculate the average and compare your score!
7
8
Return True if you're better, else False!
9
Note:
10
11
Your points are not included in the array of your class's points. For calculating the average point you may add your point to the given array!
12
*/
13
14
function betterThanAverage($classPoints, $yourPoints)
15
{
16
    $average = array_sum($classPoints)/count($classPoints);
17
    if ($average < $yourPoints) {
18
        return true;
19
    }
20
    return false;
21
}
22
23
// Alternate solution with ternary operator
24
function altbetterThanAverage($classPoints, $yourPoints)
25
{
26
    return array_sum($classPoints)/count($classPoints) < $yourPoints ? true : false;
27
}
28
29
// Another solution
30
function secaltbetterThanAverage($classPoints, $yourPoints)
31
{
32
    return array_sum($classPoints) / count($classPoints) < $yourPoints;
33
}
34