Re: Array remove duplicates question
[email protected] (ToddAndMargo via perl6-users)
| Newsgroups | perl.perl6.users |
|---|---|
| Message-ID | <[email protected]> |
On 5/6/24 03:07, ToddAndMargo via perl6-users wrote: > >>> On 6 May 2024, at 04:35, ToddAndMargo via perl6-users >>> <[email protected]> wrote: >>> >>> Hi All, >>> >>> I have thought of how to do it and pretty sure >>> it would work, but just in case Raku have one >>> of those sweet utilities, does Raku have a >>> utility that will take an array and remove all >>> the duplicates and rearrange the cells back >>> in order? >>> >>> Many thanks, >>> -T > > On 5/6/24 01:59, Elizabeth Mattijsen wrote: > > $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a' > > [1 2 3 6 7 8] > > > > https://docs.raku.org/type/Any#method_unique > > > > I knew there had to be something! Thank you! My keeper: perl6.array.duplicates.unique.txt Raku (perl6): how to remove duplicates from an array: Use `unique` and `.=` For example: $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a' [1 2 3 6 7 8] $ raku -e 'my @a = "abc","DEF","abc","jkl",1,2,8; @a .= unique; say @a' [abc DEF jkl 1 2 8] $ raku -e 'my @a = "abc","DEF","abc","jkl",1; @a .= unique; say @a' [abc DEF jkl 1] $ raku -e 'my @a = "abc","DEF","abc","jkl",1,8,1,2,8; @a .= unique; say @a' [abc DEF jkl 1 8 2]