-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_semantics_2.cairo
More file actions
38 lines (34 loc) · 993 Bytes
/
move_semantics_2.cairo
File metadata and controls
38 lines (34 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() {
// added the mutable keyword here since we need to modify the array
let mut arr0 = ArrayTrait::new();
// added the ref keyword here since we need to pass the array to the function
// without passing the ownership as we will be needing the array in
// line 11
fill_arr(ref arr0);
// Do not change the following line!
print(arr0.span());
}
// add the ref to the function parameter here
// also remove the return type of the function and also the return arr
fn fill_arr(ref arr: Array<felt252>) {
arr.append(22);
arr.append(44);
arr.append(66);
}
fn print(span: Span<felt252>) {
let mut i = 0;
print!("ARRAY: {{ len: {}, values: [ ", span.len());
loop {
if span.len() == i {
break;
}
let value = *(span.at(i));
if span.len() - 1 != i {
print!("{}, ", value);
} else {
print!("{}", value);
}
i += 1;
};
println!(" ] }}");
}