From 8b74d922b474beb7bf8a98b6e859fbb3beb64437 Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:00:41 +0900 Subject: [PATCH] mapRange --- lua/wikis/commons/Array.lua | 2 +- .../MatchGroup/Input/Custom/Normal.lua | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lua/wikis/commons/Array.lua b/lua/wikis/commons/Array.lua index bcef5aa4b22..1ff411bbf3b 100644 --- a/lua/wikis/commons/Array.lua +++ b/lua/wikis/commons/Array.lua @@ -531,7 +531,7 @@ end ---@generic T ---@param from integer ---@param to integer ----@param funct fun(index: integer): T +---@param funct fun(index: integer): T? ---@return T[] ---@nodiscard function Array.mapRange(from, to, funct) diff --git a/lua/wikis/leagueoflegends/MatchGroup/Input/Custom/Normal.lua b/lua/wikis/leagueoflegends/MatchGroup/Input/Custom/Normal.lua index 420ca3c186a..c7e0c7725c8 100644 --- a/lua/wikis/leagueoflegends/MatchGroup/Input/Custom/Normal.lua +++ b/lua/wikis/leagueoflegends/MatchGroup/Input/Custom/Normal.lua @@ -46,7 +46,7 @@ end ---@param opponentIndex integer ---@return table[]? function CustomMatchGroupInputNormal.getParticipants(map, opponentIndex) - return Logic.nilIfEmpty(Array.map(Array.range(1, MAX_NUM_PICKS), function (playerIndex) + return Logic.nilIfEmpty(Array.mapRange(1, MAX_NUM_PICKS, function (playerIndex) local playerData = Json.parseIfTable(map['t' .. opponentIndex .. 'p' .. playerIndex]) if Logic.isEmpty(playerData) then return @@ -71,24 +71,20 @@ function CustomMatchGroupInputNormal.getChampionPicks(map, opponentIndex) ---@cast participants -nil return Array.map(participants, Operator.property('character')) end - local picks = {} local teamPrefix = 't' .. opponentIndex - for playerIndex = 1, MAX_NUM_PICKS do - table.insert(picks, map[teamPrefix .. 'c' .. playerIndex]) - end - return picks + return Array.mapRange(1, MAX_NUM_PICKS, function (playerIndex) + return map[teamPrefix .. 'c' .. playerIndex] + end) end ---@param map table ---@param opponentIndex integer ---@return string[] function CustomMatchGroupInputNormal.getChampionBans(map, opponentIndex) - local bans = {} local teamPrefix = 't' .. opponentIndex - for playerIndex = 1, MAX_NUM_BANS do - table.insert(bans, map[teamPrefix .. 'b' .. playerIndex]) - end - return bans + return Array.mapRange(1, MAX_NUM_BANS, function (playerIndex) + return map[teamPrefix .. 'b' .. playerIndex] + end) end ---@param map table