Zulu - 2 months ago 16

Javascript Question

I'm trying to create an array of strings and produce the possibilities by the length of array string. For example:

`var someStr = ["a","b","c","d"];`

//I want to produce this outcome

a

ab

abc

abcd

b

bc

bcd

c

cd

d

I know I can get the # of possibilities for

`var numCombinations = 0;`

var comboString = '';

var outcome = [];

for(var i = 0; i < someStr.length; i++){

comboString += someStr[i];

outcome[i] = comboString;

numCombinations += i; //# of combinations from above

}

But how would I continue with these variables for the left over possibilities? I've thought of creating nested for-loops again and again but that would eventually lead to the

Answer Source

Hope this help.

```
function getComboStringListFromIdx(arr, idx){
var result = [];
var comboString = '';
for(var i=idx; i<arr.length; i++){
comboString += arr[i];
result.push(comboString);
}
return result;
}
var someStr = ['a','b','c','d'];
var outCome = [];
for(var i = 0; i<someStr.length; i++){
outCome = outCome.concat(getComboStringListFromIdx(someStr, i));
}
```