Can anyone take a look at my code and help me optimize it?

A search engine website wants implement a new feature that allows their users to sort their search results.

Each search result consists of a URL, a timestamp, and a relevance score. Given an array of results, the name of the column to sort by, and the sort order (ascending or descending), the page number and size of each page, implement a function that returns a list of results.

Input

sortParameter: a number representing the column to sort by: 0 = URL, 1 = timestamp, 2 = relevance

sortOrder: a number representing the sort order: 0 = ascending, 1 = descending

itemsPerPage: the number of results that is required to be displayed on a single page

pageNumber: the page number, starting from 0

items: a map of URLstrings to tuples representing the (relevance, timestamp)

Output

Return a list of URLs to be displayed.

Example:

Input:

sortParameter = 1

sortOrder = 0

itemsPerPage = 2

pageNumber= 1

items= [[“foo.com”, 10, 15], [“bar.com”, 3, 4]. [“baz.com”, 17, 8]]

Output: [“baz”]

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Got it, will keep this in mind next time. Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.