# Getting the summary

We will first need to sort our ranked sentences by their score. To do this we can use the array sort method and a fairly common numerical comparator.

```javascript
const sorted = ranked.sort((a, b) => {
  if (a.score < b.score) {
    return 1;
  } else if (a.score > b.score) {
    return -1;
  }
  return 0;
});
```

This will compare the scores and put the entries in the correct order. Once we have done this, all we need to do is take the `n` first items, where `n` is the number of sentences we want, in this case, I will take 5.

```javascript
const top5 = sorted.slice(0, 5);
console.log({ top5 });
```

And with that, you should now have a 5 sentence summary of the block of text you provided as input 🎉


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learning.pavey.dev/javascript/activities/text-summariser/getting-the-summary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
