@kourge/ordering - v2.0.0-rc.0 › "scoring" › Scoring
A scoring function Scoring<Element> offers a simpler alternative to a
Comparator. Instead of comparing two different elements, a
scoring function instead takes an element and produces a numeric score. These
scores are then used to sort compare elements against each other. This is
achieved by using the ranking function to create a
Comparator out of a scoring function.
A scoring function is called repeatedly throughout the sorting process, so
make sure that it is efficient. If it is computationally costly to calculate
the score of an element, consider using a Map or a WeakMap to cache a
score once it is calculated.
▪ Element
- Scoring
▸ (data: Element): number
A scoring function Scoring<Element> offers a simpler alternative to a
Comparator. Instead of comparing two different elements, a
scoring function instead takes an element and produces a numeric score. These
scores are then used to sort compare elements against each other. This is
achieved by using the ranking function to create a
Comparator out of a scoring function.
A scoring function is called repeatedly throughout the sorting process, so
make sure that it is efficient. If it is computationally costly to calculate
the score of an element, consider using a Map or a WeakMap to cache a
score once it is calculated.
Parameters:
| Name | Type |
|---|---|
data |
Element |
Returns: number