mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: fix reverse()
This commit is contained in:
parent
f41cf7465b
commit
ca0bae0fcd
@ -338,7 +338,7 @@ pub fn (a array) reverse() array {
|
||||
data: vcalloc(a.cap * a.element_size)
|
||||
}
|
||||
for i in 0..a.len {
|
||||
C.memcpy(arr.data + i * arr.element_size, &a.data[a.len - 1 - i], arr.element_size)
|
||||
C.memcpy(arr.data + i * arr.element_size, &a[a.len - 1 - i], arr.element_size)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
@ -259,6 +259,7 @@ fn test_reverse() {
|
||||
a := [1, 2, 3, 4]
|
||||
b := ['test', 'array', 'reverse']
|
||||
c := a.reverse()
|
||||
println(c)
|
||||
d := b.reverse()
|
||||
for i, _ in c {
|
||||
assert c[i] == a[a.len - i - 1]
|
||||
|
Loading…
Reference in New Issue
Block a user