Created
September 19, 2025 18:18
-
-
Save bastjan/9240a7cf0078c5001d32fba8b5401bc5 to your computer and use it in GitHub Desktop.
Returns all duplicates in an array based on an id function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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