Another helper function is createArray which outputs Array with numbers 1 to limit. This is simpler version of application where I only have numbers representing group members. In real life example I'll probably have list of students in text file or something like that so my Array will contain these names.
Main schedule function is simple, I just take one by one element from starter Array created using createArray function, put it in new multidimensional array and exclude it from starting one. I do this until first array is not empty.
This code will work without mistake only if remainder of n / g is zero. If it's not zero, code needs to be modified so extra elements are put in already existing groups, but equally.