String

Hi

Tthere is no string.uniq ?!?
Whats the best way to do this?

Opti

string.split('').uniq.join('') perhaps?

···

On 4/23/22 07:57, Die Optimisten wrote:

Hi

Tthere is no string.uniq ?!?
Whats the best way to do this?

Opti

Thank you, I thought of sg like that.

Another thing:
How to (best) subtract arrays that way:
a=[1,2,2,3,3], b=[1,2,3,3,4,4] => a-b = [1,2] # count is relevant
## easier way than hash with counts?

and optional: also retourning $underflow=[4,4]

# shouldn't that be added (arr-arr2 is not a set!)
Opti

Try this:

'this_is_your_string_it_is'.chars.uniq.join

   ==>"this_yourng"

···

On Fri, Apr 22, 2022 at 11:02 PM hmdne <hmdne@airmail.cc> wrote:

string.split('').uniq.join('') perhaps?

On 4/23/22 07:57, Die Optimisten wrote:
> Hi
>
> Tthere is no string.uniq ?!?
> Whats the best way to do this?
>
> Opti
>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Why should there be?!?

···

On Apr 22, 2022, at 22:58, Die Optimisten <inform@die-optimisten.net> wrote:

Tthere is no string.uniq ?!?

Hi,

To answer your first question, just do this:

str.chars.uniq.join

To answer your second question about subtracting arrays, perhaps you meant
to find the intersection of the arrays?

[1,2,2,3,3] & [1,2,3,3,4,4] # => [1,2,3]

To detect extra elements, do `b - a` (that returns `[4, 4]`) or `(b - a) +
(a - b)` for both sides if a has elements not in b too.

Cheers!

···

On Sun, Apr 24, 2022 at 5:10 AM Ryan Davis <ryand-ruby@zenspider.com> wrote:

> On Apr 22, 2022, at 22:58, Die Optimisten <inform@die-optimisten.net> > wrote:
>
> Tthere is no string.uniq ?!?

Why should there be?!?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--
Andy Maleh

LinkedIn: Andy Maleh | LinkedIn
<https://www.linkedin.com/in/andymaleh&gt;
Blog: http://andymaleh.blogspot.com
GitHub: AndyObtiva (Andy Maleh) · GitHub