mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: minor clean up
This commit is contained in:
parent
2b087dbf95
commit
c7e47e6884
@ -293,7 +293,6 @@ pub fn (a mut []int) sort() {
|
|||||||
|
|
||||||
// Looking for an array index based on value.
|
// Looking for an array index based on value.
|
||||||
// If there is, it will return the index and if not, it will return `-1`
|
// If there is, it will return the index and if not, it will return `-1`
|
||||||
// TODO: Implement for all types
|
|
||||||
pub fn (a []string) index(v string) int {
|
pub fn (a []string) index(v string) int {
|
||||||
for i := 0; i < a.len; i++ {
|
for i := 0; i < a.len; i++ {
|
||||||
if a[i] == v {
|
if a[i] == v {
|
||||||
@ -344,7 +343,7 @@ pub fn (a []string) filter(predicate fn(p_val string, p_i int, p_arr []string)
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (a []int) filter(predicate fn(p_val int, p_i int, p_arr []int) bool) []int
|
pub fn (a []int) filter(predicate fn(p_val, p_i int, p_arr []int) bool) []int
|
||||||
{
|
{
|
||||||
mut res := []int
|
mut res := []int
|
||||||
for i := 0; i < a.len; i++ {
|
for i := 0; i < a.len; i++ {
|
||||||
@ -357,13 +356,9 @@ pub fn (a []int) filter(predicate fn(p_val int, p_i int, p_arr []int) bool) []in
|
|||||||
|
|
||||||
////////////// REDUCE //////////////
|
////////////// REDUCE //////////////
|
||||||
|
|
||||||
// method executes a reducer function (that you provide) on each element of the array,
|
// Executes a reducer function (that you provide) on each element of the array,
|
||||||
// resulting in a single output value.
|
// resulting in a single output value.
|
||||||
pub fn (a []int) reduce(
|
pub fn (a []int) reduce(iter fn (accum, curr int) int, accum_start int) int {
|
||||||
iter fn (accum int, curr int) int,
|
|
||||||
accum_start int
|
|
||||||
) int
|
|
||||||
{
|
|
||||||
mut _accum := 0
|
mut _accum := 0
|
||||||
_accum = accum_start
|
_accum = accum_start
|
||||||
for i := 0; i < a.len; i++ {
|
for i := 0; i < a.len; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user