![]() |
[Hackerrank] Solution of Breaking the Records in JavaScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function breakingRecords(scores) { | |
let best = 0; | |
let worst = 0; | |
let bestScore = scores[0]; | |
let worstScore = scores[0]; | |
const lengthOfData = scores.length; | |
for(let i = 1; i < scores.length; i++) { | |
if (scores[i] > bestScore) { | |
bestScore = scores[i]; | |
best++; | |
continue; | |
} | |
if (scores[i] < worstScore) { | |
worstScore = scores[i] | |
worst++; | |
continue; | |
} | |
} | |
return [best, worst]; | |
} |