Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82cf595

Browse filesBrowse files
authored
Find attempted questions by difficulty (seanprashad#64)
* Find attempted questions by difficulty * removed unused import statement
1 parent b6b0869 commit 82cf595
Copy full SHA for 82cf595

File tree

Expand file treeCollapse file tree

1 file changed

+29
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-1
lines changed

‎src/components/Table/index.js

Copy file name to clipboardExpand all lines: src/components/Table/index.js
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ const Table = () => {
3939
checkedList = newCheckedList;
4040
window.localStorage.setItem('checked', JSON.stringify(checkedList));
4141
}
42+
const data = React.useMemo(() => questions, []);
43+
/* Get a list of all checked questions in the form of a dictionary keys as question difficulty */
44+
const checkedQuestionsByDifficulty = { Easy: 0, Hard: 0, Medium: 0 };
45+
for (let i = 0; i < checkedList.length; i += 1) {
46+
if (checkedList[i]) {
47+
checkedQuestionsByDifficulty[data[i].difficulty] += 1;
48+
}
49+
}
50+
const [checkQuestionsDict, setcheckQuestionsDict] = useState(
51+
checkedQuestionsByDifficulty,
52+
);
4253

4354
const [checked, setChecked] = useState(checkedList);
4455

@@ -54,7 +65,8 @@ const Table = () => {
5465
window.localStorage.setItem('showPatterns', JSON.stringify(showPatterns));
5566
}, [showPatterns]);
5667

57-
const data = React.useMemo(() => questions, []);
68+
/*To view the number of question solved by difficulty*/
69+
console.log(checkQuestionsDict);
5870

5971
const defaultColumn = React.useMemo(
6072
() => ({
@@ -81,6 +93,22 @@ const Table = () => {
8193
checked[cellInfo.row.original.id] = !checked[
8294
cellInfo.row.original.id
8395
];
96+
/*increment or decrement question count for the correct difficulty from the checkbox */
97+
if (checked[cellInfo.row.original.id]) {
98+
setcheckQuestionsDict(prevState => ({
99+
...prevState,
100+
[cellInfo.row.original.difficulty]:
101+
prevState[cellInfo.row.original.difficulty] + 1,
102+
}));
103+
} else {
104+
setcheckQuestionsDict(prevState => ({
105+
...prevState,
106+
[cellInfo.row.original.difficulty]:
107+
prevState[cellInfo.row.original.difficulty] === 0
108+
? 0
109+
: prevState[cellInfo.row.original.difficulty] - 1,
110+
}));
111+
}
84112
setChecked([...checked]);
85113
}}
86114
/>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.