Each day I solve several challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, but you will learn a ton of new and interesting things as you go.
This challenge starts with the declaration of a function mystery
, with one parameter arr
which is likely an array. After the function it creates an array, then calls the function, whose result goes into variable A
. Fortunately we don't have to calculate everything this code does, but only have to fix two bugs (π and π). To find π you can analyze the first three lines of code of the function, it starts with initializing variable S=0
, then later we see π += i
, so π is likely going to be S
. Then the next line is S /= arr.π;
, π seems to be a property of the array object, the only valid property from the answers seems to be length
.
If you analyze more closely at what mystery
actually does: it's summing all values from arr
into S
, and then it divides this sum by the length of the array. In other words it's computing the average value of all the numbers in arr
.
If you feel inspired and motivated to upgrade your coding + debugging skills, join me on the Road to Genius at https://nevolin.be/codr/
Top comments (0)