Nth Largest Element

Find the nth largest element in an array by sorting in descending order.

Code

General
echo "$arr" | jq --argjson n "$n" 'sort | reverse | .[$n - 1]'

Parameters

Array of numbers (JSON)

Position (1-indexed)

Server

More Bash Snippets