Prism · Real world
The top of a list
A leaderboard: sort by a field, highest first, and keep the first three.
{
players: [
{ name: 'Ada', score: 187 },
{ name: 'Grace', score: 245 },
{ name: 'Linus', score: 132 },
{ name: 'Margaret', score: 298 },
{ name: 'Donald', score: 91 },
{ name: 'Tim', score: 211 },
],
}{
$slice: {
from: {
$sortBy: {
over: { $ref: '$.players' },
as: 'p',
by: { $get: { from: { $var: 'p' }, path: ['score'] } },
dir: 'desc',
},
},
start: 0,
end: 3,
},
}[
{ name: 'Margaret', score: 298 },
{ name: 'Grace', score: 245 },
{ name: 'Tim', score: 211 },
]Runs in this page on the installed package. The input and the expected output are defined by the example.