mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: eq() for builtins (byte, string, int, i64, f32)
This commit is contained in:
parent
2798e59e7f
commit
d42c53346d
@ -365,3 +365,37 @@ pub fn (a []int) reduce(iter fn (accum, curr int) int, accum_start int) int {
|
|||||||
}
|
}
|
||||||
return _accum
|
return _accum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// []int == []int (also for: i64, f32, f64, byte, string)
|
||||||
|
fn array_eq<T>(a1, a2 []T) bool {
|
||||||
|
if a1.len != a2.len {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i < a1.len; i++ {
|
||||||
|
if a1[i] != a2[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (a []int) eq(a2 []int) bool {
|
||||||
|
return array_eq(a, a2)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (a []i64) eq(a2 []i64) bool {
|
||||||
|
return array_eq(a, a2)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (a []string) eq(a2 []string) bool {
|
||||||
|
return array_eq(a, a2)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (a []byte) eq(a2 []byte) bool {
|
||||||
|
return array_eq(a, a2)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (a []f32) eq(a2 []f32) bool {
|
||||||
|
return array_eq(a, a2)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -387,4 +387,9 @@ fn test_array_str() {
|
|||||||
assert true
|
assert true
|
||||||
assert numbers.str() == '[1, 2, 3]'
|
assert numbers.str() == '[1, 2, 3]'
|
||||||
assert numbers2.str() == '[[1, 2, 3], [4, 5, 6]]'
|
assert numbers2.str() == '[[1, 2, 3], [4, 5, 6]]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_eq() {
|
||||||
|
assert [5,6,7].eq([6,7]) == false
|
||||||
|
assert [`a`,`b`].eq([`a`,`b`]) == true
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user