• + 0 comments

    With Reduce in JS/Javascript:-

    function breakingRecords(scores) {
        const { minScoreCount, maxScoreCount } = scores.reduce((acc, score) => {
            if (acc.lastMinScore > score) { acc.minScoreCount++; acc.lastMinScore = score; }
            else if (acc.lastMaxScore < score) { acc.maxScoreCount++; acc.lastMaxScore = score; }
            return acc;
        }, {
            lastMinScore: scores[0],
            lastMaxScore: scores[0],
            minScoreCount: 0,
            maxScoreCount: 0,
        });
    
        return [maxScoreCount, minScoreCount]
    }