Skip to content

Commit

Permalink
#master: Fix len to l redeclaration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Sep 4, 2021
1 parent d7873d4 commit 445fb61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func search(needle interface{}, haystack interface{}) bool {
switch reflect.TypeOf(haystack).Kind() {
case reflect.Slice:
s := reflect.ValueOf(haystack)
len := s.Len()
l := s.Len()

for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
if needle == s.Index(i).Interface() {
return true
}
Expand All @@ -32,13 +32,13 @@ func ArrayChunk(array interface{}, size int) []interface{} {
var chunks []interface{}

s := reflect.ValueOf(array)
len := s.Len()
l := s.Len()

var subChunk []interface{}
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
subChunk = append(subChunk, s.Index(i).Interface())

if (i+1)%size == 0 || i+1 == len {
if (i+1)%size == 0 || i+1 == l {
chunks = append(chunks, subChunk)
subChunk = make([]interface{}, 0)
}
Expand All @@ -51,17 +51,17 @@ func ArrayChunk(array interface{}, size int) []interface{} {
// returns map[key]value if both slices are equal and nil otherwise
func ArrayCombine(keys interface{}, values interface{}) map[interface{}]interface{} {
s := reflect.ValueOf(keys)
len := s.Len()
l := s.Len()

ss := reflect.ValueOf(values)
ssLen := ss.Len()

if len != ssLen {
if l != ssLen {
return nil
}

resultMap := make(map[interface{}]interface{})
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
resultMap[s.Index(i).Interface()] = ss.Index(i).Interface()
}

Expand All @@ -73,8 +73,8 @@ func ArrayCountValues(array interface{}) map[interface{}]int {
res := make(map[interface{}]int)

s := reflect.ValueOf(array)
len := s.Len()
for i := 0; i < len; i++ {
l := s.Len()
for i := 0; i < l; i++ {
res[s.Index(i).Interface()]++
}

Expand All @@ -84,12 +84,12 @@ func ArrayCountValues(array interface{}) map[interface{}]int {
// ArrayMap applies the callback to the elements of the given arrays
func ArrayMap(array interface{}, callback interface{}) []interface{} {
s := reflect.ValueOf(array)
len := s.Len()
l := s.Len()

funcValue := reflect.ValueOf(callback)

var result []interface{}
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
result = append(result, funcValue.Call([]reflect.Value{s.Index(i)})[0].Interface())
}

Expand All @@ -99,12 +99,12 @@ func ArrayMap(array interface{}, callback interface{}) []interface{} {
// ArrayFilter filters elements of an array using a callback function
func ArrayFilter(array interface{}, callback interface{}) []interface{} {
s := reflect.ValueOf(array)
len := s.Len()
l := s.Len()

funcValue := reflect.ValueOf(callback)

var result []interface{}
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
if funcValue.Call([]reflect.Value{s.Index(i)})[0].Bool() {
result = append(result, s.Index(i).Interface())
}
Expand All @@ -117,12 +117,12 @@ func ArrayFilter(array interface{}, callback interface{}) []interface{} {
// returns the values in array1 that are not present in any of the other arrays
func ArrayDiff(arrays ...interface{}) []interface{} {
s := reflect.ValueOf(arrays[0])
len := s.Len()
l := s.Len()

var result []interface{}
isFound := false

for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
needle := s.Index(i).Interface()

for _, v := range arrays[1:] {
Expand Down Expand Up @@ -220,10 +220,10 @@ func ArrayUdiff(uf func(interface{}, interface{}) int, arrays ...interface{}) []
// ArraySum calculate the sum of values in an array
func ArraySum(array interface{}) (float64, error) {
s := reflect.ValueOf(array)
len := s.Len()
l := s.Len()

var amount float64
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
v, err := getFloat(s.Index(i).Interface())
if err != nil {
return v, err
Expand Down Expand Up @@ -251,13 +251,13 @@ func getFloat(unk interface{}) (float64, error) {
// ArrayIntersect computes the intersection of arrays
func ArrayIntersect(arrays ...interface{}) []interface{} {
s := reflect.ValueOf(arrays[0])
len := s.Len()
l := s.Len()

var result []interface{}
isFound := false

intersected := make(map[interface{}]bool)
for i := 0; i < len; i++ {
for i := 0; i < l; i++ {
needle := s.Index(i).Interface()

for _, v := range arrays[1:] {
Expand Down
2 changes: 1 addition & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (pq *PriorityQueue) down(i0, n int) bool {
return i > i0
}

// update modifies the Priority and Value of an Item in the queue.
//Update modifies the Priority and Value of an Item in the queue.
func (pq *PriorityQueue) Update(item *Item, value string, priority int) {
item.Value = value
item.Priority = priority
Expand Down
2 changes: 1 addition & 1 deletion date.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (t Time) Milliseconds() int64 {
return time.Time(t).UnixNano() / DivideMilliseconds
}

// Microsecond from time.Time Go type
// Microseconds from time.Time Go type
func (t Time) Microseconds() int64 {
return time.Time(t).UnixNano() / DivideMicroseconds
}
Expand Down

0 comments on commit 445fb61

Please sign in to comment.