Skip to content

Instantly share code, notes, and snippets.

@bastjan
Created September 19, 2025 18:18
Show Gist options
  • Select an option

  • Save bastjan/9240a7cf0078c5001d32fba8b5401bc5 to your computer and use it in GitHub Desktop.

Select an option

Save bastjan/9240a7cf0078c5001d32fba8b5401bc5 to your computer and use it in GitHub Desktop.
Returns all duplicates in an array based on an id function.
// Returns all duplicates in an array based on an id function.
local findDuplicates(a, id=function(o) o) =
std.foldl(
function(prev, o)
prev {
set: std.set(super.set + [ o ], id),
duplicates: super.duplicates + if std.setMember(o, super.set,id) then [ o ] else [],
},
a,
{ set: [], duplicates: [] }
).duplicates
;
findDuplicates([{a: "x"},{a: "x"},{a: "t"}], function(o) o.a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment