const scores = [7, 5, 2, 16, 23, 4, 16, 4, 25, 20];
let highestScore = scores[0];
let lowestScore = scores[0];
let highScoreRecordBreakCount = 0;
let lowScoreRecordBreakCount = 0;
for(let i = 1; i < scores.length; i++) {
if(scores[i] > highestScore ) {
highestScore = scores[i];
highScoreRecordBreakCount++;
}
if(scores[i] < lowestScore) {
lowestScore = scores[i];
lowScoreRecordBreakCount++;
}
}
console.log('highScoreRecordBreakCount:', highScoreRecordBreakCount);
console.log('lowScoreRecordBreakCount:', lowScoreRecordBreakCount);
Output:
highScoreRecordBreakCount: 3
lowScoreRecordBreakCount: 2
- From the given scores initial score is 7 and the next highest score Record is 16 and this record is broken by the score 23 and this record is broken by 25. So total 3 times the highest score record broken.
- In the same way the initial score is 6 and the next lowest record is 5 and this record is broken by the score 2. So total 2 times the lowest score record broken.