Repair this code
The starter loads a[i] before it checks anything: repair at_or_default so the element is fetched only after i is proven to be an index of a, and fallback is returned in every other case.
Steps
$ at_or_default({10, 20, 30, 40, 50}, 5, 2, -1)
30
$ at_or_default({10, 20, 30, 40, 50}, 5, -1, 777)
777
$ at_or_default({10, 20, 30, 40, 50}, 3, 3, -1)
-1
$ at_or_default(NULL, 0, 3, 1234)
1234
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers

Repair this code
The starter loads a[i] before it checks anything: repair at_or_default so the element is fetched only after i is proven to be an index of a, and fallback is returned in every other case.
Steps
$ at_or_default({10, 20, 30, 40, 50}, 5, 2, -1)
30
$ at_or_default({10, 20, 30, 40, 50}, 5, -1, 777)
777
$ at_or_default({10, 20, 30, 40, 50}, 3, 3, -1)
-1
$ at_or_default(NULL, 0, 3, 1234)
1234
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers

Tests
Run the tests to grade your code