Group Array Elements Javascript Interview Question