mirror of
https://github.com/vlang/v.git
synced 2025-09-08 23:07:19 -04:00
arrays: simplify arrays.sum and arrays.reduce (#22076)
This commit is contained in:
parent
3965a6c54f
commit
c8dc145468
@ -249,12 +249,8 @@ pub fn sum[T](array []T) !T {
|
||||
} else {
|
||||
mut head := array[0]
|
||||
|
||||
for i, e in array {
|
||||
if i == 0 {
|
||||
continue
|
||||
} else {
|
||||
head += e
|
||||
}
|
||||
for e in array[1..] {
|
||||
head += e
|
||||
}
|
||||
|
||||
return head
|
||||
@ -272,12 +268,8 @@ pub fn reduce[T](array []T, reduce_op fn (acc T, elem T) T) !T {
|
||||
} else {
|
||||
mut value := array[0]
|
||||
|
||||
for i, e in array {
|
||||
if i == 0 {
|
||||
continue
|
||||
} else {
|
||||
value = reduce_op(value, e)
|
||||
}
|
||||
for e in array[1..] {
|
||||
value = reduce_op(value, e)
|
||||
}
|
||||
|
||||
return value
|
||||
|
Loading…
x
Reference in New Issue
Block a user