# \[Help AS3\] create non-repeat combinations of multiple arrays

**URL:** <https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936>\
**Category:** flash\
**Created:** [December 9, 2021, 2:24am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936 "2021-12-09T02:24:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 9, 2021, 2:24am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/1 "2021-12-09T02:24:52Z")

</div>

Greetings all,

I have arrays like these:  
var arr1:Array = [0,1,2,3,4]  
var arr2: Array = [0,1,2,3,4,5]  
…  
var arr6:Array = [0,1,2]

How to combine all arrays into one non-repeat arrays (permutation) in AS3?  
Such as:  
var result:Array = [[0,0,0,0,0,0], [0,0,0,0,0,1], … [4,5,5,5,5,2]]

Right now I used php code to create json files of the combo.

This is php code from Stockoverflow I used.

```auto

function combinations($arrays, $i = 0) {
    if (!isset($arrays[$i])) {
        return array();
    }
    if ($i == count($arrays) - 1) {
        return $arrays[$i];
    }

    // get combinations from subsequent arrays
    $tmp = combinations($arrays, $i + 1);

    $result = array();

    // concat each array from tmp with each element from $arrays[$i]
    foreach ($arrays[$i] as $v) {
        foreach ($tmp as $t) {
            $result[] = is_array($t) ? 
                array_merge(array($v), $t) :
                array($v, $t);
        }
    }

    return $result;
}

print_r(
    combinations(
        array(
            array('A1','A2','A3'), 
            array('B1','B2','B3'), 
            array('C1','C2')
        )
    )
);

```

Thank you very much for your help.  
I am sorry for my poor English.

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 9, 2021, 12:31pm UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/2 "2021-12-09T12:31:42Z")

</div>

Thats how you could do it in JS:

```auto
function sameArray (a,b) {
    if (a.length !== b.length) return false;
    for(var i = 0; i < a.length; i++){ if (a[i] !== b[i]) return false }
    return true
}

 function addToSet(set,arr){
  for(var i = 0; i < set.length; i++){ 
    var check = sameArray(set[i],arr)
    if(check == true) return set;
   }
  return set.push(arr);
}

var set = [[1,2,3], [4,5,6]]

addToSet(set,[1,2,3]) // does not add
console.log(set)// [[ 1, 2, 3], [4, 5, 6] ]

addToSet(set, [7,8,9]) // adds to myArraySet
console.log(set) // [[ 1, 2, 3], [4, 5, 6], [7, 8, 9] ]

```

I’m taking a punt here (I know JS and some Rust) but maybe this is how it would look in AS3 with the type annotations:

```auto
function sameArray (a:Array, b:Array):Boolean {
    if (a.length != b.length) return false;
    for(var i:int = 0; i < a.length; i++){ if (a[i] !== b[i]) return false }
    return true
}

 function addToSet(set:Array, arr:Array):Array{
  for(var i:int = 0; i < set.length; i++){ 
    var check:Boolean = sameArray(set[i] ,arr)
    if(check == true) return set;
   }
  return set.push(arr);
}

var set:Array = [[1,2,3], [4,5,6]]

addToSet(set,[1,2,3]) // does not add

addToSet(set, [7,8,9]) // adds to myArraySet

```

@kirupa and @senocular would know if that would work.

---

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 9, 2021, 3:17pm UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/3 "2021-12-09T15:17:16Z")

</div>

Thank you for the help @steve.mills  
Actually that’s not i want. I am sorry I didn’t explain it well.  
It is a permutation of multiple arrays. I want to create a combination of each array’s values.

From these arrays:  
var arr1 =[0,1]  
var arr2 = [0,1,2]

I expect an array like this:

```auto
[[0, 0],
    [0, 1],
    [0, 2],
    [1, 0],
    [1, 1],
    [1, 2] ]

```

Please look at the attached image. I hope it explains better.

 ![img](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/9/b/9b5fa35a46ecfb2de83fbcc7abcd711b1701c399.jpeg)

Yes… i am creating NFT generator.

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 2:30am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/4 "2021-12-10T02:30:10Z")

</div>

NW,  
It looks like there could be some constraints on this.

For example your folders start at 0 and the files start at 1. If your array was `[2,0]` it won’t match because the files start at 1.

Also how high do your files numbers go 1-9? 1-99? 1-999?  
Will each folder contain the same amount of files? e.g. 0/1-9, 1/1-9?

The following will do what you want in JS and I’ve kept it older style JS to make easy conversion to AS3

```auto

var arr1 = [1,2,3,4]
var arr2 = [3,4,5,6]
var arr3 = [5,6,7,8]

// creates a set in an Array (like new Set([]), then Array.from(set))
function arraySet(arr){
  let acc = []
  for(var i = 0; i < arr.length; i++){
    var check = acc.indexOf(arr[i])
    if (check >= 0){ continue}
    else{ acc.push(arr[i])}
  }
  return acc.sort()
}

// does a first pass of the base Set (creates [1,2] arrays)
function permutations (arr){
  let acc = []
  for(var i = 0; i < arr.length; i++){
    for(var j = 0; j < arr.length; j++){
      var per = [];
      per.push(arr[i], arr[j]);
      acc.push(per) 
    }
  }
  return acc
}

// does a second pass of the Set (creates [1,2,3] arrays)
function addPerms(base,set){
  let acc = [];
  for(var i = 0; i < set.length; i++){
    for(var j = 0; j < base.length; j++){
      var clone = [];
      var perm = set[i];
      for(var k = 0; k < perm.length; k++){
        clone.push(perm[k])
      }
      clone.push(base[j]);
      acc.push(clone);
    }
  }
  return acc
}

// does a second pass of the Set but creates double digit second numbers ([1,25] arrays)
function doublePass (base,set){
  let acc = [];
  for(var i = 0; i < set.length; i++){
    for(var j = 0; j < base.length; j++){
        var clone = [];
        var perm = set[i];
      for(var k = 0; k < perm.length -1; k++){
        clone.push(perm[k])
      }
        var conc = "" + clone[clone.length - 1] + base[j];
        var int = parseInt(conc);
        clone.push(int);
        acc.push(clone);
    }
  }
  return acc
}

// first concat all input arrays
let conc = arr1.concat(arr2,arr3)

//create an array Set from conc
let set = arraySet(conc);

// creates first pass permutations from Set
let test = permutations(set);
//console.log(test)

// creates second or third pass of permutations
let second1 = addPerms(conc,test)
console.log(second1)

// creates a double digit second or third pass
let second = doublePass(conc,test)
console.log(second)

```

Just add the type annotations and return values to the functions and type annotations to the internal variables.

Also maybe change the `let` to `var`.

IDK if AS3 supports `parseInt()` or type coercion var `conc = "" + clone[clone.length - 1] + base[j];` to string.

I think `Array.sort()` should be fine but maybe it takes different args.

---

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 10, 2021, 4:21am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/5 "2021-12-10T04:21:28Z")

</div>

Thank you @steve.mills  
Let me clear up some contraints.

> [@steve.mills](#):
>
> For example your folders start at 0 and the files start at 1. If your array was `[2,0]` it won’t match because the files start at 1.

The array always starts from 0 and ends at array length-1.  
The image arrays may look like these (no number in the names):  
var arr1 = [“bluebg.png”, “ambience.png”, “bokeh.png”]  
var arr2 = [“funkmech.png”, “crazymech.png”, “liquidmech.png”, “steelmech.png”]  
So the combo [2,0] means [“bokeh.png”, “funkmech.png”]

> [@](#):
>
> Also how high do your files numbers go 1-9? 1-99? 1-999?  
> Will each folder contain the same amount of files? e.g. 0/1-9, 1/1-9?

It depends on how many images inside a folder. I’ll make sure the number is below 9 to make permutations not exceed 10000.  
The number of images in each folder is not the same. One folder may contains 3 images, another has 9 images …

> [@](#):
>
> The following will do what you want in JS and I’ve kept it older style JS to make easy conversion to AS3
> 
> ```auto
> 
> var arr1 = [1,2,3,4]
> var arr2 = [3,4,5,6]
> var arr3 = [5,6,7,8]
> 
> // creates a set in an Array (like new Set([]), then Array.from(set))
> function arraySet(arr){
> let acc = []
> for(var i = 0; i < arr.length; i++){
> var check = acc.indexOf(arr[i])
> if (check >= 0){ continue}
> else{ acc.push(arr[i])}
> }
> return acc.sort()
> }
> 
> // does a first pass of the base Set (creates [1,2] arrays)
> function permutations (arr){
> let acc = []
> for(var i = 0; i < arr.length; i++){
> for(var j = 0; j < arr.length; j++){
> var per = [];
> per.push(arr[i], arr[j]);
> acc.push(per) 
> }
> }
> return acc
> }
> 
> // does a second pass of the Set (creates [1,2,3] arrays)
> function addPerms(base,set){
> let acc = [];
> for(var i = 0; i < set.length; i++){
> for(var j = 0; j < base.length; j++){
> var clone = [];
> var perm = set[i];
> for(var k = 0; k < perm.length; k++){
> clone.push(perm[k])
> }
> clone.push(base[j]);
> acc.push(clone);
> }
> }
> return acc
> }
> 
> // does a second pass of the Set but creates double digit second numbers ([1,25] arrays)
> function doublePass (base,set){
> let acc = [];
> for(var i = 0; i < set.length; i++){
> for(var j = 0; j < base.length; j++){
> var clone = [];
> var perm = set[i];
> for(var k = 0; k < perm.length -1; k++){
> clone.push(perm[k])
> }
> var conc = "" + clone[clone.length - 1] + base[j];
> var int = parseInt(conc);
> clone.push(int);
> acc.push(clone);
> }
> }
> return acc
> }
> 
> // first concat all input arrays
> let conc = arr1.concat(arr2,arr3)
> 
> //create an array Set from conc
> let set = arraySet(conc);
> 
> // creates first pass permutations from Set
> let test = permutations(set);
> //console.log(test)
> 
> // creates second or third pass of permutations
> let second1 = addPerms(conc,test)
> console.log(second1)
> 
> // creates a double digit second or third pass
> let second = doublePass(conc,test)
> console.log(second)
> 
> ```
> 
> Just add the type annotations and return values to the functions and type annotations to the internal variables.
> 
> Also maybe change the `let` to `var`.
> 
> IDK if AS3 supports `parseInt()` or type coercion var `conc = "" + clone[clone.length - 1] + base[j];` to string.
> 
> I think `Array.sort()` should be fine but maybe it takes different args.

I will look at the code. Thank you very much for your time and assistance in this matter

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 6:04am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/6 "2021-12-10T06:04:04Z")

</div>

The idea is:

- concat your input arrays
- create a Set in an array
- loop the Set and for each index → loop the entire set again making permutations and pushing to `acc`
- loop the created `permutation set` and either `push` another base number to the Set ([1,2,3]) or use another function and `push` a number like [1,18] to the set

```auto
var arr1:Array = [1,2,3,4]
var arr2:Array = [3,4,5,6]
var arr3:Array = [5,6,7,8]

// creates a set in an Array (like new Set([]), then Array.from(set))
function arraySet(arr:Array) :Array {
  let acc:Array = []
  for(var i;int = 0; i < arr.length; i++){
    var check:float = acc.indexOf(arr[i])
    if (check >= 0){ continue}
    else{ acc.push(arr[i])}
  }
  return acc.sort()
}

// does a first pass of the base Set (creates [1,2] arrays)
function permutations (arr:Array) :Array {
  let acc:Array = []
  for(var i:int = 0; i < arr.length; i++){
    for(var j:int = 0; j < arr.length; j++){
      var per:Array = [];
      per.push(arr[i], arr[j]);
      acc.push(per) 
    }
  }
  return acc
}

// does a second pass of the Set (creates [1,2,3] arrays)
function addPerms(base:Array,set:Array):Array {
  let acc:Array = [];
  for(var i:int = 0; i < set.length; i++){
    for(var j:int = 0; j < base.length; j++){
      var clone:Array = [];
      var perm:Array = set[i];
      for(var k:int = 0; k < perm.length; k++){
        clone.push(perm[k])
      }
      clone.push(base[j]);
      acc.push(clone);
    }
  }
  return acc
}

// does a second pass of the Set but creates double digit second numbers ([1,25] arrays)
function doublePass (base:Array,set:Array):Array {
  let acc:Array = [];
  for(var i:int = 0; i < set.length; i++){
    for(var j:int = 0; j < base.length; j++){
        var clone:Array = [];
        var perm:Array = set[i];
      for(var k:int = 0; k < perm.length -1; k++){
        clone.push(perm[k])
      }
        var conc:string = "" + clone[clone.length - 1] + base[j];
        var inte:int = parseInt(conc);
        clone.push(inte);
        acc.push(clone);
    }
  }
  return acc
}

// first concat all input arrays
var conc:Array = arr1.concat(arr2,arr3)

//create an array Set from conc
var set:Array = arraySet(conc);

// creates first pass permutations from Set
var test:Array = permutations(set);

// creates second or third pass of permutations
let second1:Array = addPerms(conc,test)

// creates a double digit second or third pass
let second:Array = doublePass(conc,test)

```

---

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 10, 2021, 6:27am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/7 "2021-12-10T06:27:54Z")

</div>

> [@steve.mills](#):
>
> ```auto
> var arr1:Array = [1,2,3,4]
> var arr2:Array = [3,4,5,6]
> var arr3:Array = [5,6,7,8]
> 
> // creates a set in an Array (like new Set([]), then Array.from(set))
> function arraySet(arr:Array) :Array {
> let acc:Array = []
> for(var i;int = 0; i < arr.length; i++){
> var check:float = acc.indexOf(arr[i])
> if (check >= 0){ continue}
> else{ acc.push(arr[i])}
> }
> return acc.sort()
> }
> 
> ```

This is the result of the code. I think it is different from the expected array.

 ![res](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/8/9/896c3532ed3de14cc4900bd1f37e961fa650a125.jpeg)  
This is three first array of the result  
[[1,1,1], [1,1,2], [1,1,3] … ]  
from these arrays:  
var arr1:Array = [1,2,3,4]  
var arr2:Array = [3,4,5,6]  
var arr3:Array = [5,6,7,8]  
It should be: [[1,3,5], [2,3,5], [3,3,5] … ]

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 6:53am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/8 "2021-12-10T06:53:25Z")

</div>

The first pass I get this (JS)

```auto
[
  [1, 1], [1, 2], [1, 3], [1, 4], [1, 5],
  [1, 6], [1, 7], [1, 8], [2, 1], [2, 2],
  [2, 3], [2, 4], [2, 5], [2, 6], [2, 7],
  [2, 8], [3, 1], [3, 2], [3, 3], [3, 4],
  [3, 5], [3, 6], [3, 7], [3, 8], [4, 1],
  [4, 2], [4, 3], [4, 4], [4, 5], [4, 6],
  [4, 7], [4, 8], [5, 1], [5, 2], [5, 3],
  [5, 4], [5, 5], [5, 6], [5, 7], [5, 8],
  [6, 1], [6, 2], [6, 3], [6, 4], [6, 5],
  [6, 6], [6, 7], [6, 8], [7, 1], [7, 2],
  [7, 3], [7, 4], [7, 5], [7, 6], [7, 7],
  [7, 8], [8, 1], [8, 2], [8, 3], [8, 4],
  [8, 5], [8, 6], [8, 7], [8, 8]
]

```

from `let test = permutations(set);`

correct me if I’m wrong you want every possible combination in order?

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 7:17am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/9 "2021-12-10T07:17:23Z")

</div>

The second pass will give you this:  
from this: `let second1 = addPerms(conc,test)`

```auto
[
  [1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 1, 4],
  [1, 1, 3], [1, 1, 4], [1, 1, 5], [1, 1, 6],
  [1, 1, 5], [1, 1, 6], [1, 1, 7], [1, 1, 8],
  [1, 2, 1], [1, 2, 2], [1, 2, 3], [1, 2, 4],
  [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6],
  [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 2, 8],
  [1, 3, 1], [1, 3, 2], [1, 3, 3], [1, 3, 4],
  [1, 3, 3], [1, 3, 4], [1, 3, 5], [1, 3, 6],
  [1, 3, 5], [1, 3, 6], [1, 3, 7], [1, 3, 8],
  [1, 4, 1], [1, 4, 2], [1, 4, 3], [1, 4, 4],
  [1, 4, 3], [1, 4, 4], [1, 4, 5], [1, 4, 6],
  [1, 4, 5], [1, 4, 6], [1, 4, 7], [1, 4, 8],
  [1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4],
  [1, 5, 3], [1, 5, 4], [1, 5, 5], [1, 5, 6],
  [1, 5, 5], [1, 5, 6], [1, 5, 7], [1, 5, 8],
  [1, 6, 1], [1, 6, 2], [1, 6, 3], [1, 6, 4],
  [1, 6, 3], [1, 6, 4], [1, 6, 5], [1, 6, 6],
  [1, 6, 5], [1, 6, 6], [1, 6, 7], [1, 6, 8],
  [1, 7, 1], [1, 7, 2], [1, 7, 3], [1, 7, 4],
  [1, 7, 3], [1, 7, 4], [1, 7, 5], [1, 7, 6],
  [1, 7, 5], [1, 7, 6], [1, 7, 7], [1, 7, 8],
  [1, 8, 1], [1, 8, 2], [1, 8, 3], [1, 8, 4],
  [1, 8, 3], [1, 8, 4], [1, 8, 5], [1, 8, 6],
  [1, 8, 5], [1, 8, 6], [1, 8, 7], [1, 8, 8],
  [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 1, 4],
  [2, 1, 3], [2, 1, 4], [2, 1, 5], [2, 1, 6],
  [2, 1, 5], [2, 1, 6], [2, 1, 7], [2, 1, 8],
  [2, 2, 1], [2, 2, 2], [2, 2, 3], [2, 2, 4],
  [2, 2, 3], [2, 2, 4], [2, 2, 5], [2, 2, 6],
  [2, 2, 5], [2, 2, 6], [2, 2, 7], [2, 2, 8],
  [2, 3, 1], [2, 3, 2], [2, 3, 3], [2, 3, 4],
  [2, 3, 3], [2, 3, 4], [2, 3, 5], [2, 3, 6],
  [2, 3, 5], [2, 3, 6], [2, 3, 7], [2, 3, 8],
  [2, 4, 1], [2, 4, 2], [2, 4, 3], [2, 4, 4],
  [2, 4, 3], [2, 4, 4], [2, 4, 5], [2, 4, 6],
  [2, 4, 5], [2, 4, 6], [2, 4, 7], [2, 4, 8],
  [2, 5, 1], [2, 5, 2], [2, 5, 3], [2, 5, 4],
  [2, 5, 3], [2, 5, 4], [2, 5, 5], [2, 5, 6],
  [2, 5, 5], [2, 5, 6], [2, 5, 7], [2, 5, 8],
  [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4],
  [2, 6, 3], [2, 6, 4], [2, 6, 5], [2, 6, 6],
  [2, 6, 5], [2, 6, 6], [2, 6, 7], [2, 6, 8],
  [2, 7, 1], [2, 7, 2], [2, 7, 3], [2, 7, 4],
  [2, 7, 3], [2, 7, 4], [2, 7, 5], [2, 7, 6],
  [2, 7, 5], [2, 7, 6], [2, 7, 7], [2, 7, 8],
  [2, 8, 1], [2, 8, 2], [2, 8, 3], [2, 8, 4],
  [2, 8, 3], [2, 8, 4], [2, 8, 5], [2, 8, 6],
  [2, 8, 5], [2, 8, 6], [2, 8, 7], [2, 8, 8],
  [3, 1, 1], [3, 1, 2], [3, 1, 3], [3, 1, 4],
  [3, 1, 3], [3, 1, 4], [3, 1, 5], [3, 1, 6],
  [3, 1, 5], [3, 1, 6], [3, 1, 7], [3, 1, 8],
  [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 2, 4],
  [3, 2, 3], [3, 2, 4], [3, 2, 5], [3, 2, 6],
  [3, 2, 5], [3, 2, 6], [3, 2, 7], [3, 2, 8],
  [3, 3, 1], [3, 3, 2], [3, 3, 3], [3, 3, 4],
  [3, 3, 3], [3, 3, 4], [3, 3, 5], [3, 3, 6],
  [3, 3, 5], [3, 3, 6], [3, 3, 7], [3, 3, 8],
  [3, 4, 1], [3, 4, 2], [3, 4, 3], [3, 4, 4],
  [3, 4, 3], [3, 4, 4], [3, 4, 5], [3, 4, 6],
  [3, 4, 5], [3, 4, 6], [3, 4, 7], [3, 4, 8],
  [3, 5, 1], [3, 5, 2], [3, 5, 3], [3, 5, 4],
  [3, 5, 3], [3, 5, 4], [3, 5, 5], [3, 5, 6],
  [3, 5, 5], [3, 5, 6], [3, 5, 7], [3, 5, 8],
  [3, 6, 1], [3, 6, 2], [3, 6, 3], [3, 6, 4],
  [3, 6, 3], [3, 6, 4], [3, 6, 5], [3, 6, 6],
  [3, 6, 5], [3, 6, 6], [3, 6, 7], [3, 6, 8],
  [3, 7, 1], [3, 7, 2], [3, 7, 3], [3, 7, 4],
  [3, 7, 3], [3, 7, 4], [3, 7, 5], [3, 7, 6],
  [3, 7, 5], [3, 7, 6], [3, 7, 7], [3, 7, 8],
  [3, 8, 1], [3, 8, 2], [3, 8, 3], [3, 8, 4],
  [3, 8, 3], [3, 8, 4], [3, 8, 5], [3, 8, 6],
  [3, 8, 5], [3, 8, 6], [3, 8, 7], [3, 8, 8],
  [4, 1, 1], [4, 1, 2], [4, 1, 3], [4, 1, 4],
  [4, 1, 3], [4, 1, 4], [4, 1, 5], [4, 1, 6],
  [4, 1, 5], [4, 1, 6], [4, 1, 7], [4, 1, 8],
  [4, 2, 1], [4, 2, 2], [4, 2, 3], [4, 2, 4],
  [4, 2, 3], [4, 2, 4], [4, 2, 5], [4, 2, 6],
  [4, 2, 5], [4, 2, 6], [4, 2, 7], [4, 2, 8],
  [4, 3, 1], [4, 3, 2], [4, 3, 3], [4, 3, 4],
  [4, 3, 3], [4, 3, 4], [4, 3, 5], [4, 3, 6],
  [4, 3, 5], [4, 3, 6], [4, 3, 7], [4, 3, 8],
  [4, 4, 1], [4, 4, 2], [4, 4, 3], [4, 4, 4],
  [4, 4, 3], [4, 4, 4], [4, 4, 5], [4, 4, 6],
  [4, 4, 5], [4, 4, 6], [4, 4, 7], [4, 4, 8],
  [4, 5, 1], [4, 5, 2], [4, 5, 3], [4, 5, 4],
  [4, 5, 3], [4, 5, 4], [4, 5, 5], [4, 5, 6],
  [4, 5, 5], [4, 5, 6], [4, 5, 7], [4, 5, 8],
  [4, 6, 1], [4, 6, 2], [4, 6, 3], [4, 6, 4],
  [4, 6, 3], [4, 6, 4], [4, 6, 5], [4, 6, 6],
  [4, 6, 5], [4, 6, 6], [4, 6, 7], [4, 6, 8],
  [4, 7, 1], [4, 7, 2], [4, 7, 3], [4, 7, 4],
  [4, 7, 3], [4, 7, 4], [4, 7, 5], [4, 7, 6],
  [4, 7, 5], [4, 7, 6], [4, 7, 7], [4, 7, 8],
  [4, 8, 1], [4, 8, 2], [4, 8, 3], [4, 8, 4],
  [4, 8, 3], [4, 8, 4], [4, 8, 5], [4, 8, 6],
  [4, 8, 5], [4, 8, 6], [4, 8, 7], [4, 8, 8],
  [5, 1, 1], [5, 1, 2], [5, 1, 3], [5, 1, 4],
  [5, 1, 3], [5, 1, 4], [5, 1, 5], [5, 1, 6],
  [5, 1, 5], [5, 1, 6], [5, 1, 7], [5, 1, 8],
  [5, 2, 1], [5, 2, 2], [5, 2, 3], [5, 2, 4],
  [5, 2, 3], [5, 2, 4], [5, 2, 5], [5, 2, 6],
  [5, 2, 5], [5, 2, 6], [5, 2, 7], [5, 2, 8],
  [5, 3, 1], [5, 3, 2], [5, 3, 3], [5, 3, 4],
  [5, 3, 3], [5, 3, 4], [5, 3, 5], [5, 3, 6],
  [5, 3, 5], [5, 3, 6], [5, 3, 7], [5, 3, 8],
  [5, 4, 1], [5, 4, 2], [5, 4, 3], [5, 4, 4],
  [5, 4, 3], [5, 4, 4], [5, 4, 5], [5, 4, 6],
  [5, 4, 5], [5, 4, 6], [5, 4, 7], [5, 4, 8],
  [5, 5, 1], [5, 5, 2], [5, 5, 3], [5, 5, 4],
  [5, 5, 3], [5, 5, 4], [5, 5, 5], [5, 5, 6],
  [5, 5, 5], [5, 5, 6], [5, 5, 7], [5, 5, 8],
  [5, 6, 1], [5, 6, 2], [5, 6, 3], [5, 6, 4],
  [5, 6, 3], [5, 6, 4], [5, 6, 5], [5, 6, 6],
  [5, 6, 5], [5, 6, 6], [5, 6, 7], [5, 6, 8],
  [5, 7, 1], [5, 7, 2], [5, 7, 3], [5, 7, 4],
  [5, 7, 3], [5, 7, 4], [5, 7, 5], [5, 7, 6],
  [5, 7, 5], [5, 7, 6], [5, 7, 7], [5, 7, 8],
  [5, 8, 1], [5, 8, 2], [5, 8, 3], [5, 8, 4],
  [5, 8, 3], [5, 8, 4], [5, 8, 5], [5, 8, 6],
  [5, 8, 5], [5, 8, 6], [5, 8, 7], [5, 8, 8],
  [6, 1, 1], [6, 1, 2], [6, 1, 3], [6, 1, 4],
  [6, 1, 3], [6, 1, 4], [6, 1, 5], [6, 1, 6],
  [6, 1, 5], [6, 1, 6], [6, 1, 7], [6, 1, 8],
  [6, 2, 1], [6, 2, 2], [6, 2, 3], [6, 2, 4],
  [6, 2, 3], [6, 2, 4], [6, 2, 5], [6, 2, 6],
  [6, 2, 5], [6, 2, 6], [6, 2, 7], [6, 2, 8],
  [6, 3, 1], [6, 3, 2], [6, 3, 3], [6, 3, 4],
  [6, 3, 3], [6, 3, 4], [6, 3, 5], [6, 3, 6],
  [6, 3, 5], [6, 3, 6], [6, 3, 7], [6, 3, 8],
  [6, 4, 1], [6, 4, 2], [6, 4, 3], [6, 4, 4],
  [6, 4, 3], [6, 4, 4], [6, 4, 5], [6, 4, 6],
  [6, 4, 5], [6, 4, 6], [6, 4, 7], [6, 4, 8],
  [6, 5, 1], [6, 5, 2], [6, 5, 3], [6, 5, 4],
  [6, 5, 3], [6, 5, 4], [6, 5, 5], [6, 5, 6],
  [6, 5, 5], [6, 5, 6], [6, 5, 7], [6, 5, 8],
  [6, 6, 1], [6, 6, 2], [6, 6, 3], [6, 6, 4],
  [6, 6, 3], [6, 6, 4], [6, 6, 5], [6, 6, 6],
  [6, 6, 5], [6, 6, 6], [6, 6, 7], [6, 6, 8],
  [6, 7, 1], [6, 7, 2], [6, 7, 3], [6, 7, 4],
  [6, 7, 3], [6, 7, 4], [6, 7, 5], [6, 7, 6],
  [6, 7, 5], [6, 7, 6], [6, 7, 7], [6, 7, 8],
  [6, 8, 1], [6, 8, 2], [6, 8, 3], [6, 8, 4],
  [6, 8, 3], [6, 8, 4], [6, 8, 5], [6, 8, 6],
  [6, 8, 5], [6, 8, 6], [6, 8, 7], [6, 8, 8],
  [7, 1, 1], [7, 1, 2], [7, 1, 3], [7, 1, 4],
  [7, 1, 3], [7, 1, 4], [7, 1, 5], [7, 1, 6],
  [7, 1, 5], [7, 1, 6], [7, 1, 7], [7, 1, 8],
  [7, 2, 1], [7, 2, 2], [7, 2, 3], [7, 2, 4],
  [7, 2, 3], [7, 2, 4], [7, 2, 5], [7, 2, 6],
  [7, 2, 5], [7, 2, 6], [7, 2, 7], [7, 2, 8],
  [7, 3, 1], [7, 3, 2], [7, 3, 3], [7, 3, 4],
  [7, 3, 3], [7, 3, 4], [7, 3, 5], [7, 3, 6],
  [7, 3, 5], [7, 3, 6], [7, 3, 7], [7, 3, 8],
  [7, 4, 1], [7, 4, 2], [7, 4, 3], [7, 4, 4],
  [7, 4, 3], [7, 4, 4], [7, 4, 5], [7, 4, 6],
  [7, 4, 5], [7, 4, 6], [7, 4, 7], [7, 4, 8],
  [7, 5, 1], [7, 5, 2], [7, 5, 3], [7, 5, 4],
  [7, 5, 3], [7, 5, 4], [7, 5, 5], [7, 5, 6],
  [7, 5, 5], [7, 5, 6], [7, 5, 7], [7, 5, 8],
  [7, 6, 1], [7, 6, 2], [7, 6, 3], [7, 6, 4],
  [7, 6, 3], [7, 6, 4], [7, 6, 5], [7, 6, 6],
  [7, 6, 5], [7, 6, 6], [7, 6, 7], [7, 6, 8],
  [7, 7, 1], [7, 7, 2], [7, 7, 3], [7, 7, 4],
  [7, 7, 3], [7, 7, 4], [7, 7, 5], [7, 7, 6],
  [7, 7, 5], [7, 7, 6], [7, 7, 7], [7, 7, 8],
  [7, 8, 1], [7, 8, 2], [7, 8, 3], [7, 8, 4],
  [7, 8, 3], [7, 8, 4], [7, 8, 5], [7, 8, 6],
  [7, 8, 5], [7, 8, 6], [7, 8, 7], [7, 8, 8],
  [8, 1, 1], [8, 1, 2], [8, 1, 3], [8, 1, 4],
  [8, 1, 3], [8, 1, 4], [8, 1, 5], [8, 1, 6],
  [8, 1, 5], [8, 1, 6], [8, 1, 7], [8, 1, 8],
  [8, 2, 1], [8, 2, 2], [8, 2, 3], [8, 2, 4],
  [8, 2, 3], [8, 2, 4], [8, 2, 5], [8, 2, 6],
  [8, 2, 5], [8, 2, 6], [8, 2, 7], [8, 2, 8],
  [8, 3, 1], [8, 3, 2], [8, 3, 3], [8, 3, 4],
  [8, 3, 3], [8, 3, 4], [8, 3, 5], [8, 3, 6],
  [8, 3, 5], [8, 3, 6], [8, 3, 7], [8, 3, 8],
  [8, 4, 1], [8, 4, 2], [8, 4, 3], [8, 4, 4],
  [8, 4, 3], [8, 4, 4], [8, 4, 5], [8, 4, 6],
  [8, 4, 5], [8, 4, 6], [8, 4, 7], [8, 4, 8],
  [8, 5, 1], [8, 5, 2], [8, 5, 3], [8, 5, 4],
  [8, 5, 3], [8, 5, 4], [8, 5, 5], [8, 5, 6],
  [8, 5, 5], [8, 5, 6], [8, 5, 7], [8, 5, 8],
  [8, 6, 1], [8, 6, 2], [8, 6, 3], [8, 6, 4],
  [8, 6, 3], [8, 6, 4], [8, 6, 5], [8, 6, 6],
  [8, 6, 5], [8, 6, 6], [8, 6, 7], [8, 6, 8],
  [8, 7, 1], [8, 7, 2], [8, 7, 3], [8, 7, 4],
  [8, 7, 3], [8, 7, 4], [8, 7, 5], [8, 7, 6],
  [8, 7, 5], [8, 7, 6], [8, 7, 7], [8, 7, 8],
  [8, 8, 1], [8, 8, 2], [8, 8, 3], [8, 8, 4],
  [8, 8, 3], [8, 8, 4], [8, 8, 5], [8, 8, 6],
  [8, 8, 5], [8, 8, 6], [8, 8, 7], [8, 8, 8]
]

```

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 7:21am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/10 "2021-12-10T07:21:37Z")

</div>

■■■■, there’s a few double ups. This is going to need to be nested 4 deep 😁

---

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 10, 2021, 9:08am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/11 "2021-12-10T09:08:02Z")

</div>

the second one is the closest one.  
I too tested second1 = addPerms(conc,test).  
This array: [1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 1, 4]… is unexpected.  
The second element of each “child” array should be from second array of your example which is var arr2:Array = [3,4,5,6]. The third should be from 3rd array: [5,6,7,8]

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 11:49am UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/12 "2021-12-10T11:49:35Z")

</div>

Ok my bad, this is what you want.

- input 5 arrays
- output nested arrays for every combo of the 5

in JS:

```auto
function perms(one, two, three, four, five){
  var acc = [];
  for(var i = 0; i < one.length; i++){
    for(var j = 0; j < two.length; j++){
      for(var k = 0; k < three.length; k++){
        for(var l = 0; l < four.length; l++){
          for(var m = 0; m < five.length; m++){
            var perm = [];
            perm.push(one[i],two[j],three[k],four[l],five[m]);
            acc.push(perm)
          } 
        }
      }
    }
  }
  return acc;
}

```

Equivalent in AS3 I think

```auto
function perms(one:Array, two:Array, three:Array, four:Array, five:Array):Array{
  var acc:Array = [];
  for(var i:int = 0; i < one.length; i++){
    for(var j:int = 0; j < two.length; j++){
      for(var k:int = 0; k < three.length; k++){
        for(var l:int = 0; l < four.length; l++){
          for(var m:int = 0; m < five.length; m++){
            var perm:Array = [];
            perm.push(one[i],two[j],three[k],four[l],five[m]);
            acc.push(perm)
          } 
        }
      }
    }
  }
  return acc;
}

```

---

<div class="post-metadata">

**Author:** ![Nayzuko](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nayzuko/32/16185_2.png) [@Nayzuko](https://forum.kirupa.com/u/Nayzuko)\
**Post date:** [December 10, 2021, 12:13pm UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/13 "2021-12-10T12:13:22Z")

</div>

> [@steve.mills](#):
>
> ```auto
> function perms(one:Array, two:Array, three:Array, four:Array, five:Array):Array{
> var acc:Array = [];
> for(var i:int = 0; i < one.length; i++){
> for(var j:int = 0; j < two.length; j++){
> for(var k:int = 0; k < three.length; k++){
> for(var l:int = 0; l < four.length; l++){
> for(var m:int = 0; m < five.length; m++){
> var perm:Array = [];
> perm.push(one[i],two[j],three[k],four[l],five[m]);
> acc.push(perm)
> } 
> }
> }
> }
> }
> return acc;
> }
> 
> ```

Yes… your code works. its output is the expected array.  
Thank you very much for your help and patience.  
@steve.mills, you are awesome!

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [December 10, 2021, 12:17pm UTC](https://forum.kirupa.com/t/help-as3-create-non-repeat-combinations-of-multiple-arrays/649936/14 "2021-12-10T12:17:44Z")

</div>

Your welcome, I like a puzzle 🙂
