# Ranking Tools

> Ranking Tools is a library of reusable functions and constants for other scripts.

Source: https://algobarsx.com/docs/ex-59-ranking-tools-library/

```algobarsx
library "Ranking Tools"

type Scored:
    symbol: symbol
    score: number

fn top_n(items: list<Scored>, n: int) -> list<Scored>:
    return items.sort_by(item => item.score).keep_last(n)

fn normalize(value: number, low: number, high: number) -> number:
    if high == low:
        return 0
    return clamp((value - low) / (high - low), 0, 1)

fn percentile_band(source: series<number> = close, length: int = 100) -> number:
    return percentile(source, length, percent: 90%) - percentile(source, length, percent: 10%)
```
What this script says

Ranking Tools is a library of reusable functions and constants for other scripts.

It defines `top_n(items, n)`, which returns `list<Scored>`, `normalize(value, low, high)`, which returns a number and `percentile_band(source, length)`, which returns a number.
