Finished
44//
55
66export class HighScores {
7 constructor() {
8 throw new Error('Remove this line and implement the function');
7 constructor(scores) {
8 this._scores = scores;
99 }
1010
1111 get scores() {
12 throw new Error('Remove this line and implement the function');
12 return this._scores;
1313 }
1414
1515 get latest() {
16 throw new Error('Remove this line and implement the function');
16 // Edge Case: empty score list
17 if (this._scores.length === 0) {
18 return undefined;
19 }
20 return this._scores[this._scores.length - 1];
1721 }
1822
1923 get personalBest() {
20 throw new Error('Remove this line and implement the function');
24 // Edge Case: empty score list
25 if (this._scores.length === 0) {
26 return undefined;
27 }
28 return Math.max(...this._scores);
2129 }
2230
2331 get personalTopThree() {
24 throw new Error('Remove this line and implement the function');
32 // Edge Case: empty score list
33 if (this._scores.length === 0) {
34 return [];
35 }
36 // Create a copy of the array and sort in descending order
37 const sortedScores = [...this._scores].sort((a, b) => b - a);
38 // Return the first three elements (or all if fewer than three)
39 return sortedScores.slice(0, 3);
2540 }
2641}
42
43// Handled Edge Cases: empty score list, single score in list, duplicate scores, negative scores, list with fewer than three scores
Test NameStatus
List of scores
Pass
Latest score
Pass
Personal best
Pass
Personal top three from a list of scores
Pass
Personal top highest to lowest
Pass
Personal top when there is a tie
Pass
Personal top when there are less than 3
Pass
Personal top when there is only one
Pass
Latest score after personal top scores
Pass
Scores after personal top scores
Pass
Latest score after personal best
Pass
Scores after personal best
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.