Sort array based on clicked