Challenge: Write an Extension Function to Reverse an Array

Test your understanding of extension functions by solving the challenge given in this lesson.

Problem statement

Implement an extension function, reverseArray(), for the intArray class, to reverse the order of a given array.

Sample test case

This is how we’ll test the extension function:

var array = intArrayOf(1, 3, 4, 6, 7)

Expected output

array => [7, 6, 4, 3, 1]

Business logic

The following illustration shows one of the ways to accomplishthis:

Get hands-on with 1200+ tech skills courses.