function checks if current index is >= to lenght then it returns to calling part.
other wise it adds current index array value to 0th index of result array
it also build a string of array values and store in 1st index of result array.

Now index value is increment and again same function is called with incremented index value.