
September 1997. The USS Yorktown, a Navy cruiser running a Windows NT Smart Ship control system, takes a zero typed into a database field. A calculation divides by that zero, the error cascades through the propulsion software, and a billion dollar warship sits dead in the water, towed back to port. The whole ship was stopped by one unchecked denominator. Guard the division.
Repair this code
Repair the average so an empty array returns 0 instead of dividing by zero.
Steps
$ average({10,20,30}, 3)
20
$ average({}, 0)
0
$ average({1,2,3,4}, 4)
2
Expected files
Allowed functions
None. Write every helper yourself.
Loading solutions...