What is the most efficient way of extracting some common (group) value from array and create a new array based on group, where each group element is preceding elements that