1
+ // Create a new variable to store all solutions
2
+ const allSolutions = [ ] as { id : number , title : string , url : string } [ ] ;
1
3
const solutions = [ ] as { id : number , title : string , url : string } [ ] ;
2
4
3
5
let companyName = 'Amazon' ;
@@ -72,6 +74,25 @@ function addNavbarLinks() {
72
74
} ) ;
73
75
}
74
76
77
+ interface Company {
78
+ name : string ;
79
+ }
80
+
81
+ interface Question {
82
+ title : string ;
83
+ frontend_id : number ;
84
+ companies ?: Company [ ] ;
85
+ }
86
+
87
+ interface LeetcodeProblems {
88
+ questions : Question [ ] ;
89
+ }
90
+
91
+ let minFrequency = Number . MAX_SAFE_INTEGER ;
92
+ let maxFrequency = 0 ;
93
+
94
+
95
+
75
96
async function updateFrequency ( selectedFrequency : string ) {
76
97
// Clear the existing table
77
98
const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
@@ -83,6 +104,9 @@ async function updateFrequency(selectedFrequency: string) {
83
104
minFrequency = Number . MAX_SAFE_INTEGER ;
84
105
maxFrequency = 0 ;
85
106
107
+ // Create a new array to hold the solutions with the selected frequency
108
+ const updatedSolutions = [ ] ;
109
+
86
110
// Update the frequency values in the solutions array
87
111
const data = await new Promise < { companyProblems : any } > ( ( resolve ) => {
88
112
chrome . storage . local . get ( 'companyProblems' , function ( data ) {
@@ -92,7 +116,7 @@ async function updateFrequency(selectedFrequency: string) {
92
116
93
117
const companyProblems = data . companyProblems [ companyName ] ;
94
118
if ( Array . isArray ( companyProblems ) ) {
95
- solutions . forEach ( ( solution , index ) => {
119
+ allSolutions . forEach ( ( solution , index ) => { // Iterate over allSolutions
96
120
// Check if the selected frequency value exists for the problem
97
121
if ( companyProblems [ index ] . hasOwnProperty ( selectedFrequency ) ) {
98
122
const freqValue = companyProblems [ index ] [ selectedFrequency ] ;
@@ -101,32 +125,22 @@ async function updateFrequency(selectedFrequency: string) {
101
125
// Update min and max frequency for the selected range
102
126
if ( freqValue < minFrequency ) minFrequency = freqValue ;
103
127
if ( freqValue > maxFrequency ) maxFrequency = freqValue ;
128
+
129
+ // Add the solution to the updated solutions array
130
+ updatedSolutions . push ( solution ) ;
104
131
}
105
132
} ) ;
106
133
}
107
134
135
+ // Replace the solutions array with the updated solutions
136
+ solutions . length = 0 ;
137
+ solutions . push ( ...updatedSolutions ) ;
138
+
108
139
// Rebuild the table with updated frequency values
109
140
rebuildTable ( ) ;
110
141
}
111
142
112
143
113
- interface Company {
114
- name : string ;
115
- }
116
-
117
- interface Question {
118
- title : string ;
119
- frontend_id : number ;
120
- companies ?: Company [ ] ;
121
- }
122
-
123
- interface LeetcodeProblems {
124
- questions : Question [ ] ;
125
- }
126
-
127
- let minFrequency = Number . MAX_SAFE_INTEGER ;
128
- let maxFrequency = 0 ;
129
-
130
144
function addCompanyProblems ( sortMethod : string ) {
131
145
chrome . storage . local . get ( [ 'companyProblems' , 'leetcodeProblems' ] , function ( data ) {
132
146
const companyProblems = data . companyProblems [ companyName ] ;
@@ -139,14 +153,15 @@ function addCompanyProblems(sortMethod: string) {
139
153
// Check if companyProblems is an array before proceeding
140
154
if ( Array . isArray ( companyProblems ) ) {
141
155
companyProblems . forEach ( ( problem ) => {
142
- const correspondingLeetcodeProblem = leetcodeProblems . find ( q => q . frontend_id === problem . id ) ;
143
- solutions . push ( {
156
+ const correspondingLeetcodeProblem = leetcodeProblems . find ( q => q . frontend_id === problem . id ) ; // Find the corresponding problem
157
+ // Populate allSolutions instead of solutions
158
+ allSolutions . push ( {
144
159
id : problem . id ,
145
160
title : problem . title ,
146
161
url : `https://leetcode.com/problems/${ problem . title . replace ( / \s / g, '-' ) } /` ,
147
162
frequency : problem . freq_alltime ,
148
- difficulty : correspondingLeetcodeProblem ?. difficulty_lvl , // Add difficulty
149
- acceptance : correspondingLeetcodeProblem ?. acceptance , // Add acceptance
163
+ difficulty : correspondingLeetcodeProblem ?. difficulty_lvl , // Use the defined variable
164
+ acceptance : correspondingLeetcodeProblem ?. acceptance , // Use the defined variable
150
165
} ) ;
151
166
152
167
// Update min and max frequency
@@ -155,64 +170,17 @@ function addCompanyProblems(sortMethod: string) {
155
170
} ) ;
156
171
}
157
172
173
+ // Initialize solutions with all problems initially
174
+ solutions . length = 0 ;
175
+ solutions . push ( ...allSolutions ) ;
176
+
158
177
console . log ( solutions ) ;
159
178
160
179
// Rebuild the table with sorted solutions
161
180
rebuildTable ( ) ;
162
-
163
181
} ) ;
164
182
}
165
183
166
- async function addCompaniesToSelect ( ) {
167
- const companySearch = document . getElementById ( 'companySearch' ) as HTMLInputElement ;
168
- const companyList = document . getElementById ( 'companyList' ) as HTMLDataListElement ;
169
- let companies = [ ] ;
170
-
171
- const data = await new Promise < { companyProblems : any } > ( ( resolve ) => {
172
- chrome . storage . local . get ( 'companyProblems' , function ( data ) {
173
- resolve ( data ) ;
174
- } ) ;
175
- } ) ;
176
-
177
- const companyProblems = data . companyProblems ;
178
- // add all the keys to the set
179
- Object . keys ( companyProblems ) . forEach ( ( company ) => {
180
- if ( company ) {
181
- console . log ( company ) ;
182
- companies . push ( company ) ;
183
- }
184
- } ) ;
185
-
186
- // Event when the "Enter" key is pressed or an option is selected from the dropdown
187
- const handleSelection = ( ) => {
188
- const inputValue = companySearch . value ;
189
- // Find the selected company in a case-insensitive manner
190
- const selectedCompany = Array . from ( companies ) . find (
191
- ( company ) => company . toLowerCase ( ) === inputValue . toLowerCase ( )
192
- ) ;
193
- if ( selectedCompany ) {
194
- chrome . storage . local . set ( { clickedCompany : selectedCompany } , ( ) => {
195
- location . reload ( ) ;
196
- } ) ;
197
- }
198
- } ;
199
-
200
- companySearch . addEventListener ( 'keydown' , ( event ) => {
201
- if ( event . key === 'Enter' ) {
202
- handleSelection ( ) ;
203
- }
204
- } ) ;
205
-
206
- companySearch . addEventListener ( 'change' , handleSelection ) ;
207
-
208
- const sortedCompanies = companies . sort ( ) ;
209
-
210
- sortedCompanies . forEach ( ( company ) => {
211
- const option = document . createElement ( 'option' ) ;
212
- option . value = company ;
213
- companyList . appendChild ( option ) ;
214
- } ) ;
215
- }
216
184
217
185
// Function to rebuild the table with sorted solutions
218
186
function rebuildTable ( ) {
@@ -312,7 +280,6 @@ function sortBy(column: string) {
312
280
313
281
// Rebuild the table with sorted solutions
314
282
rebuildTable ( ) ;
315
-
316
283
}
317
284
318
285
/* Run the script */
0 commit comments