implementation of flatToNested Array