Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Raku: How to divide every element in array by a certain number?

I have an array:

my @e = <60.922    20.946     8.721     7.292     4.306     2.821     2.765     2.752     2.741     2.725>

I would like to divide every element in the array by the minimum, however

@e /= @e.min

produced a single element, which isn’t correct.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve read https://docs.raku.org/type/Array but I don’t understand the basic elements of Raku for this.

How can I divide every item in the array by the same number?

>Solution :

my @a = 2, 3, 5, 7, 10;
my $div = @a.min;
$_ /= $div for @a;
say @a;  # [1 1.5 2.5 3.5 5]

When you iterate over an array, you get mutable elements.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading