Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -1,9 +1,9 @@
|
|||
var arr = [1,2,3,4,5];
|
||||
var arr = [1,2,3,4,5]
|
||||
|
||||
# Creates a new array
|
||||
var new = arr.grep {|i| i %% 2};
|
||||
say new.dump; # => [2, 4]
|
||||
var new = arr.grep {|i| i.is_even }
|
||||
say new # => [2, 4]
|
||||
|
||||
# Destructive (at variable level)
|
||||
arr.grep! {|i| i %% 2};
|
||||
say arr.dump; # => [2, 4]
|
||||
arr.grep! {|i| i.is_even }
|
||||
say arr # => [2, 4]
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
fn reduce(mut a []int){
|
||||
mut last := 0
|
||||
for e in a {
|
||||
if e%2==0 {
|
||||
if e % 2 == 0 {
|
||||
a[last] = e
|
||||
last++
|
||||
}
|
||||
}
|
||||
a = a[..last]
|
||||
a = a[..last].clone()
|
||||
}
|
||||
fn main() {
|
||||
mut nums := [5,4,8,2,4,6,5,6,34,12,21]
|
||||
even := nums.filter(it%2==0)
|
||||
println('orig: $nums')
|
||||
println('even: $even')
|
||||
mut nums := [5, 4, 8, 2, 4, 6, 5, 6, 34, 12, 21]
|
||||
even := nums.filter(it % 2 == 0)
|
||||
println('orig: ${nums}')
|
||||
println('even: ${even}')
|
||||
reduce(mut nums)
|
||||
println('dest: $nums')
|
||||
println('dest: ${nums}')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue