Using Reduce Method Javascript Array Sort Function