Write a function named getPaginatedData
that is used to get a certain page from a sorted Array of items.
The function should receive 5 parameters:
users
, each with the following propertiesid
- a stringname
- a stringage
- a numbersortBy
- the name of a property inside a user objectdirection
in which we want to sort the users
array. This parameter can have only 2 values: "asc" or "desc"perPage
pageNumber
The function should return a new Array of objects representing the users that are on the requested page.
users
=sortBy
=direction
=perPage
=pageNumber
=We first sort the Array descending by age. Then we split it into pages of 2 elements. This gives us 3 pages. The last page contains one user: Luna