Skip to content

Commit

Permalink
use Array.reverse and Array.map
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Oct 25, 2024
1 parent ca5897d commit 8fbd997
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions contracts/ArrayUtils.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ access(all) contract ArrayUtils {
}

access(all) fun reverse(_ array: [Int]): [Int] {
var res: [Int] = []
let length = array.length
if length > 0 {
for i in InclusiveRange(length - 1, 0) {
res.append(array[i])
}
}
return res
return array.reverse()
}

access(all) fun transform(
Expand All @@ -50,19 +43,11 @@ access(all) contract ArrayUtils {
}

access(all) fun map(_ array: [AnyStruct], _ f: fun (AnyStruct): AnyStruct): [AnyStruct] {
var res: [AnyStruct] = []
for item in array {
res.append(f(item))
}
return res
return array.map(f)
}

access(all) fun mapStrings(_ array: [String], _ f: fun (String): String): [String] {
var res: [String] = []
for item in array {
res.append(f(item))
}
return res
return array.map(f)
}

access(all) fun reduce(_
Expand Down

0 comments on commit 8fbd997

Please sign in to comment.