From 8fbd997ddf42d464e0a06df922547c742b841265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 25 Oct 2024 10:02:10 -0700 Subject: [PATCH] use Array.reverse and Array.map --- contracts/ArrayUtils.cdc | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/contracts/ArrayUtils.cdc b/contracts/ArrayUtils.cdc index a05a7af..5f81e0c 100644 --- a/contracts/ArrayUtils.cdc +++ b/contracts/ArrayUtils.cdc @@ -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( @@ -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(_