index-number methode: countValleys improved