Skip to content

Commit 5ffa139

Browse files
authored
Flow Action: Shuffle List and Create Matches (#1470)
* Create Readme.md Create Shuffle Matches Readme File * Create Shuffle Array Matches.js Script to Shuffle a List of SysIDs and create matches of 2. * Update Readme.md Updated description and title * Update Shuffle Array Matches.js Updated Code
1 parent acb9282 commit 5ffa139

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Shuffle Array Matches
2+
Flow Action: inputs of a List of SysID's and it creates a Shuffled Arrays, Matches of 2 sysIDs
3+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function execute(inputs, outputs) {
2+
function shuffleArray(array) {
3+
for (var i = array.length - 1; i > 0; i--) {
4+
var j = Math.floor(Math.random() * (i + 1));
5+
var temp = array[i];
6+
array[i] = array[j];
7+
array[j] = temp;
8+
}
9+
return array;
10+
}
11+
12+
function createRandomPairs(array) {
13+
var shuffledArray = shuffleArray(array.slice()); // Make a copy of the array and shuffle it
14+
var pairs = [];
15+
for (var i = 0; i < shuffledArray.length; i += 2) {
16+
if (i + 1 < shuffledArray.length) {
17+
pairs.push([shuffledArray[i], shuffledArray[i + 1]]);
18+
} else {
19+
pairs.push([shuffledArray[i]]);
20+
}
21+
}
22+
return pairs;
23+
}
24+
25+
26+
var randomPairs = createRandomPairs(inputs.wheels);
27+
28+
29+
30+
outputs.match = randomPairs;
31+
32+
})(inputs, outputs);

0 commit comments

Comments
 (0)