Skip to content

Commit c69bd2f

Browse files
committed
add problem rank to problems by company page
1 parent c43d772 commit c69bd2f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/problems-by-company/company.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h1 id="title">Amazon</h1>
2020
<th id="Difficulty" class="header">Difficulty</th>
2121
<th id="Title" class="header">Title</th>
2222
<th id="Acceptance" class="header">Acceptance</th>
23+
<th id="Rank" class="header">Rank</th>
2324
</tr>
2425
</table>
2526
<script src="../../dist/problems-by-company/company.js"></script>

src/problems-by-company/company.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
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 }[];
53
let companyName = 'Amazon';
64
const companies = [
75
'Amazon', 'Apple', 'Facebook', 'Google', 'Microsoft', 'Netflix'
@@ -18,6 +16,7 @@ async function main() {
1816

1917
document.getElementById('#')?.addEventListener('click', () => sortBy('#'));
2018
document.getElementById('Difficulty')?.addEventListener('click', () => sortBy('Difficulty'));
19+
document.getElementById('Rank')?.addEventListener('click', () => sortBy('Rank'));
2120
document.getElementById('Title')?.addEventListener('click', () => sortBy('Title'));
2221
document.getElementById('Acceptance')?.addEventListener('click', () => sortBy('Acceptance'));
2322

@@ -94,6 +93,7 @@ function addCompanyProblems(sortMethod: string) {
9493
// Populate allSolutions instead of solutions
9594
allSolutions.push({
9695
id: problem.id,
96+
rank: problem.rank,
9797
title: problem.title,
9898
url: `https://leetcode.com/problems/${problem.title.replace(/\s/g, '-')}/`,
9999
difficulty: correspondingLeetcodeProblem?.difficulty_lvl, // Use the defined variable
@@ -121,15 +121,16 @@ function rebuildTable() {
121121

122122
solutions.forEach((solution) => {
123123
const row = table.insertRow(-1);
124+
125+
// Add problem id
124126
row.insertCell(0).innerText = solution.id.toString();
125127

126-
// Get the difficulty level
128+
// Add problem difficulty
127129
const difficulty = solution.difficulty;
128130
const difficultyCell = row.insertCell(1);
129131
let difficultyText = '';
130132
let color = '';
131133

132-
// Define the difficulty text and background color
133134
if (difficulty === 1) {
134135
difficultyText = 'Easy';
135136
color = 'lightgreen';
@@ -147,12 +148,17 @@ function rebuildTable() {
147148
difficultyCell.style.fontSize = '12px';
148149
difficultyCell.style.borderRadius = '5px'; // Apply border radius
149150

151+
// Add problem title
150152
row.insertCell(2).innerHTML = `<a href="${solution.url}" target="_blank">${solution.title}</a>`;
151153

152154
// Add acceptance rating
153155
const acceptanceCell = row.insertCell(3);
154156
acceptanceCell.innerText = (solution.acceptance ? (solution.acceptance * 100).toFixed(2) + '%' : 'N/A'); // New column for acceptance
155157
acceptanceCell.style.fontSize = '12px';
158+
159+
// Add problem rank
160+
const rankCell = row.insertCell(4);
161+
rankCell.innerText = solution.rank.toString();
156162
});
157163
}
158164

@@ -213,6 +219,7 @@ const sortOrders = {
213219
'Difficulty': false,
214220
'Title': false,
215221
'Acceptance': false,
222+
'Rank': false,
216223
};
217224

218225
function sortBy(column: string) {
@@ -234,6 +241,9 @@ function sortBy(column: string) {
234241
solutions.sort((a, b) => (sortOrders[column] ? a.title.localeCompare(b.title) : b.title.localeCompare(a.title)));
235242
solutions.sort((a, b) => (sortOrders[column] ? a.difficulty - b.difficulty : b.difficulty - a.difficulty));
236243
break;
244+
case 'Rank':
245+
solutions.sort((a, b) => (sortOrders[column] ? a.rank - b.rank : b.rank - a.rank));
246+
break;
237247
case 'Title':
238248
solutions.sort((a, b) => (sortOrders[column] ? a.title.localeCompare(b.title) : b.title.localeCompare(a.title)));
239249
break;

0 commit comments

Comments
 (0)