DEV Community

duccanhole
duccanhole

Posted on

code every day with me

--DAY 8--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
-Problem: Breaking the Records
-Detail: https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
-My solution (javascript):

function breakingRecords(scores) {
    let min=scores[0],max=scores[0];
    let ans=[0,0];
    for(let i=1;i<scores.length;i++){
        if(scores[i]>max){
            ans[0]++;
            max=scores[i];
        }
        else if(scores[i]<min){
            ans[1]++;
            min=scores[i];
        }
    }
    return ans;
}
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Top comments (0)