How would I go about this? I tried using the std/algorithm sort and sorted proc, but they yielded me some quite unhelpful compilation errors.
here is an example of the objects:
type
Package* = object
Name* : string
Description* : string
Version* : string
URLPath* : string
LastModified* : int
NumVotes* : int
and here is an example of a sequence of two of the objects:
@[(Name: "fastfetch-git", Description: "Like neofetch, but much faster because written in c", Version: "1.5.1.r0.gdbe24c7-1", URLPath: "/cgit/aur.git/snapshot/fastfetch-git.tar.gz", LastModified: 1654681264, NumVotes: 11), (Name: "fastfetch", Description: "Like Neofetch, but much faster because written in C", Version: "1.5.6-1", URLPath: "/cgit/aur.git/snapshot/fastfetch.tar.gz", LastModified: 1656861723, NumVotes: 7)]
import std/algorithm
type
Package* = object
Name* : string
Description* : string
Version* : string
URLPath* : string
LastModified* : int
NumVotes* : int
# fastfetch has less votes
var pkgs = @[
Package(Name: "fastfetch", Description: "Like Neofetch, but much faster because written in C", Version: "1.5.6-1", URLPath: "/cgit/aur.git/snapshot/fastfetch.tar.gz", LastModified: 1656861723, NumVotes: 7),
Package(Name: "fastfetch-git", Description: "Like neofetch, but much faster because written in c", Version: "1.5.1.r0.gdbe24c7-1", URLPath: "/cgit/aur.git/snapshot/fastfetch-git.tar.gz", LastModified: 1654681264, NumVotes: 11)
]
proc cmpPkgs(a, b: Package): int =
cmp(a.NumVotes, b.NumVotes)
pkgs.sort(cmpPkgs, Descending)
echo pkgs[0].Name
But please don't use PascalCase field names as the fields in the object :)
Oh my goodness, thank you so much for the help, it worked like a charm!
PS: I totally forgot about the field names, they were only like that because I was originally filling them directly from JSON, was dying to change them, thanks for the reminder!