From 6851d6f93bb3ceb035262c4eaf9672895c041e21 Mon Sep 17 00:00:00 2001 From: Daniel Maldonado Date: Thu, 2 Oct 2025 17:08:37 -0400 Subject: [PATCH 1/3] Create README.md Readme file for the Arry matched function --- .../Flow Actions/Create an Array of Item Pairs/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md diff --git a/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md new file mode 100644 index 0000000000..7eaff9f079 --- /dev/null +++ b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md @@ -0,0 +1,2 @@ +# Shuffle Array Matches +Flow Action: inputs of a List of SysID's and it creates a Shuffled Arrays, Matches of 2 sysIDs From 91c7634ce713dcf7e2bd321d9993da886dd4ebd2 Mon Sep 17 00:00:00 2001 From: Daniel Maldonado Date: Thu, 2 Oct 2025 17:12:23 -0400 Subject: [PATCH 2/3] Create Shuffle Array Pairs Updated code script --- .../Shuffle Array Pairs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Specialized Areas/Flow Actions/Create an Array of Item Pairs/Shuffle Array Pairs diff --git a/Specialized Areas/Flow Actions/Create an Array of Item Pairs/Shuffle Array Pairs b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/Shuffle Array Pairs new file mode 100644 index 0000000000..3ed4612e7e --- /dev/null +++ b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/Shuffle Array Pairs @@ -0,0 +1,32 @@ +(function execute(inputs, outputs) { + function shuffleArray(array) { + for (var i = array.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + return array; +} + +function createRandomPairs(array) { + var shuffledArray = shuffleArray(array.slice()); // Make a copy of the array and shuffle it + var pairs = []; + for (var i = 0; i < shuffledArray.length; i += 2) { + if (i + 1 < shuffledArray.length) { + pairs.push([shuffledArray[i], shuffledArray[i + 1]]); + } else { + pairs.push([shuffledArray[i]]); + } + } + return pairs; +} + + +var randomPairs = createRandomPairs(inputs.wheels); + + + + outputs.match = randomPairs; + +})(inputs, outputs); From a804c3ca1cf47896558e4bdd8a5244be404b43fe Mon Sep 17 00:00:00 2001 From: Daniel Maldonado Date: Thu, 2 Oct 2025 17:13:52 -0400 Subject: [PATCH 3/3] Update README.md updated read me --- .../Create an Array of Item Pairs/README.md | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md index 7eaff9f079..1344f6bc48 100644 --- a/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md +++ b/Specialized Areas/Flow Actions/Create an Array of Item Pairs/README.md @@ -1,2 +1,21 @@ -# Shuffle Array Matches -Flow Action: inputs of a List of SysID's and it creates a Shuffled Arrays, Matches of 2 sysIDs +# Random Pair Generator + +## Overview +This script generates random pairs from an input array. +It is useful for creating **tournament matches**, **group assignments**, or **randomized pairings**. + +The script is structured to run in a scoped execution context (such as **ServiceNow Flow Designer Actions** or **Scripted REST Transforms**) where it accepts `inputs` and `outputs` objects. + +--- + +## How It Works +1. **Shuffle the Input Array** + - Implements the Fisher–Yates algorithm in `shuffleArray()` to randomize the array. + +2. **Create Random Pairs** + - Iterates through the shuffled array in steps of two. + - Forms pairs `[item1, item2]`. + - If the array has an odd length, the last item is placed in a single-element array `[item]`. + +3. **Return Results** + - The final set of pairs is returned as `outputs.match`.