Solution: Extension Operators

In this section, you will explore the solution for the extension operators' challenge.

Solution: Extension Operators

In this lesson, you will explore the solution to the “Extension Operators” challenge.

Solution #1

The first challenge is to implement the - operator to reverse the order of items in the given list. The operator keyword is used before the -(). The reversed property of List is called on the this object to reverse the given list.

Solution #2

In Challenge #2, we wanted to reverse the list of a different data type num. The reversed property returns an Iterable object. We should declare Iterable to return a generic type by using T to support different data types.

Check out the solutions in the code snippet below.

Get hands-on with 1200+ tech skills courses.