1
- // Create a new variable to store all solutions
2
- const allSolutions = [ ] as { id : number , title : string , url : string } [ ] ;
3
- const solutions = [ ] as { id : number , title : string , url : string } [ ] ;
4
-
1
+ const allSolutions = [ ] as { id : number , rank : number , title : string , difficulty : string , url : string , acceptance : string } [ ] ;
2
+ const solutions = [ ] as { id : number , rank : number , title : string , difficulty : string , url : string , acceptance : string } [ ] ;
5
3
let companyName = 'Amazon' ;
6
4
const companies = [
7
5
'Amazon' , 'Apple' , 'Facebook' , 'Google' , 'Microsoft' , 'Netflix'
@@ -18,6 +16,7 @@ async function main() {
18
16
19
17
document . getElementById ( '#' ) ?. addEventListener ( 'click' , ( ) => sortBy ( '#' ) ) ;
20
18
document . getElementById ( 'Difficulty' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Difficulty' ) ) ;
19
+ document . getElementById ( 'Rank' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Rank' ) ) ;
21
20
document . getElementById ( 'Title' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Title' ) ) ;
22
21
document . getElementById ( 'Acceptance' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Acceptance' ) ) ;
23
22
@@ -94,6 +93,7 @@ function addCompanyProblems(sortMethod: string) {
94
93
// Populate allSolutions instead of solutions
95
94
allSolutions . push ( {
96
95
id : problem . id ,
96
+ rank : problem . rank ,
97
97
title : problem . title ,
98
98
url : `https://leetcode.com/problems/${ problem . title . replace ( / \s / g, '-' ) } /` ,
99
99
difficulty : correspondingLeetcodeProblem ?. difficulty_lvl , // Use the defined variable
@@ -121,15 +121,16 @@ function rebuildTable() {
121
121
122
122
solutions . forEach ( ( solution ) => {
123
123
const row = table . insertRow ( - 1 ) ;
124
+
125
+ // Add problem id
124
126
row . insertCell ( 0 ) . innerText = solution . id . toString ( ) ;
125
127
126
- // Get the difficulty level
128
+ // Add problem difficulty
127
129
const difficulty = solution . difficulty ;
128
130
const difficultyCell = row . insertCell ( 1 ) ;
129
131
let difficultyText = '' ;
130
132
let color = '' ;
131
133
132
- // Define the difficulty text and background color
133
134
if ( difficulty === 1 ) {
134
135
difficultyText = 'Easy' ;
135
136
color = 'lightgreen' ;
@@ -147,12 +148,17 @@ function rebuildTable() {
147
148
difficultyCell . style . fontSize = '12px' ;
148
149
difficultyCell . style . borderRadius = '5px' ; // Apply border radius
149
150
151
+ // Add problem title
150
152
row . insertCell ( 2 ) . innerHTML = `<a href="${ solution . url } " target="_blank">${ solution . title } </a>` ;
151
153
152
154
// Add acceptance rating
153
155
const acceptanceCell = row . insertCell ( 3 ) ;
154
156
acceptanceCell . innerText = ( solution . acceptance ? ( solution . acceptance * 100 ) . toFixed ( 2 ) + '%' : 'N/A' ) ; // New column for acceptance
155
157
acceptanceCell . style . fontSize = '12px' ;
158
+
159
+ // Add problem rank
160
+ const rankCell = row . insertCell ( 4 ) ;
161
+ rankCell . innerText = solution . rank . toString ( ) ;
156
162
} ) ;
157
163
}
158
164
@@ -213,6 +219,7 @@ const sortOrders = {
213
219
'Difficulty' : false ,
214
220
'Title' : false ,
215
221
'Acceptance' : false ,
222
+ 'Rank' : false ,
216
223
} ;
217
224
218
225
function sortBy ( column : string ) {
@@ -234,6 +241,9 @@ function sortBy(column: string) {
234
241
solutions . sort ( ( a , b ) => ( sortOrders [ column ] ? a . title . localeCompare ( b . title ) : b . title . localeCompare ( a . title ) ) ) ;
235
242
solutions . sort ( ( a , b ) => ( sortOrders [ column ] ? a . difficulty - b . difficulty : b . difficulty - a . difficulty ) ) ;
236
243
break ;
244
+ case 'Rank' :
245
+ solutions . sort ( ( a , b ) => ( sortOrders [ column ] ? a . rank - b . rank : b . rank - a . rank ) ) ;
246
+ break ;
237
247
case 'Title' :
238
248
solutions . sort ( ( a , b ) => ( sortOrders [ column ] ? a . title . localeCompare ( b . title ) : b . title . localeCompare ( a . title ) ) ) ;
239
249
break ;
0 commit comments