filter.sf 262 B

12345678910111213141516
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Filter
  4. #
  5. var arr = [1,2,3,4,5];
  6.  
  7. # Creates a new array
  8. var new = arr.grep {|i| i %% 2};
  9. say new.dump; # => [2, 4]
  10.  
  11. # Destructive (at variable level)
  12. arr.grep! {|i| i %% 2};
  13. say arr.dump; # => [2, 4]