Skip to content

Commit 63d12f7

Browse files
committed
add method count in options, closes #20
1 parent 5597506 commit 63d12f7

3 files changed

Lines changed: 59 additions & 30 deletions

File tree

details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<option value="string">String</option>
7676
<option value="array">Array/List</option>
7777
<option value="object">Object/Dict</option>
78-
<option value="class">Class*</option>
78+
<option value="class">Class</option>
7979
<option value="api">API/HTTP</option>
8080
</select>
8181
</fieldset>

js/data/detailsPreEls.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44

55
const JavaScript = {
6-
'number': [
7-
'min',
8-
'max',
9-
'floor',
10-
'random',
11-
'sqrt',
12-
'pow',
13-
'round',
6+
"number": [
7+
'Math.min',
8+
'Math.max',
9+
'Math.floor',
10+
'Math.random',
11+
'Math.sqrt',
12+
'Math.pow',
13+
'Math.round',
1414
'toFixed',
1515
'toPrecision',
1616
'parseInt',
@@ -572,20 +572,18 @@ const user = new User("Luna", "luna@email.com", "abc123");
572572
],
573573
"api": [
574574
{
575-
"keywords": ["fetch", "async/await", "try/catch", "json"],
575+
"keywords": ["Basic Fetch"],
576576
"code": `
577577
const DOMAIN = 'https://example.com';
578578
579579
async function fetchData(endpoint) {
580580
try {
581581
const response = await fetch(DOMAIN + endpoint);
582-
583582
if (!response.ok) {
584583
throw new Error(\`Response status: \${response.status}\`);
585584
}
586585
587586
const data = await response.json();
588-
589587
console.log(data);
590588
return data;
591589
} catch (err) {
@@ -894,7 +892,7 @@ user = User("Luna", "luna@email.com", "abc123")
894892
],
895893
"api": [
896894
{
897-
"keywords": ["requests", "get", "json", "try", "except"],
895+
"keywords": ["Basic Fetch"],
898896
"code": `
899897
import requests
900898
@@ -1236,7 +1234,7 @@ $user = new User("Luna", "luna@email.com", "abc123");
12361234
],
12371235
"api": [
12381236
{
1239-
"keywords": ["file_get_contents", "stream_context_create", "print_r", "json_decode", "Exception", "try/catch"],
1237+
"keywords": ["Basic Fetch"],
12401238
"code": `
12411239
function fetchData($endpoint) {
12421240
$url = 'https://example.com' . $endpoint;
@@ -1629,7 +1627,7 @@ User user = new User("Luna", "luna@email.com", "abc123");
16291627
],
16301628
"api": [
16311629
{
1632-
"keywords": ["HttpClient", "GetAsync", "await", "async", "try", "catch", "json"],
1630+
"keywords": ["Basic Fetch", "json"],
16331631
"code": `
16341632
using System;
16351633
using System.Net.Http;

js/details.js

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const languages = {
2727
CSharp
2828
};
2929

30+
const structures = ["number", "string", "array", "object", "class", "api"]
31+
3032
/**
3133
* * DOM ELEMENT FUNCTIONS
3234
*/
@@ -117,24 +119,53 @@ function createOptions() {
117119
// Only populate if we have a valid data type
118120
if (langObj && selectedDataType && langObj[selectedDataType]) {
119121
langObj[selectedDataType].forEach(method => {
120-
const option = document.createElement('option');
121-
option.textContent = method;
122-
option.value = method;
123-
methodsSelect.append(option);
122+
123+
const count = getMethodUseCount(method);
124+
125+
const option = document.createElement('option');
126+
option.textContent = `${method} (${count})`;
127+
option.value = method;
128+
129+
methodsSelect.append(option);
124130
});
125131
}
126132
}
127133

128-
// 5. Get data types length by language
129-
function getDataTypeLen() {
130-
console.log(detailsPre["JavaScript"]["number"].length); // 7
131-
console.log(detailsPre["JavaScript"]["string"].length); // 9
132-
console.log(detailsPre["JavaScript"]["array"].length); // 11
133-
console.log(detailsPre["JavaScript"]["object"].length); // 3
134-
console.log(detailsPre["JavaScript"]["class"].length); // 4
135-
console.log(detailsPre["JavaScript"]["api"].length); // 4
134+
// 5. Get the count of how many times the methods occurs in "keywords"
135+
// function getMthodUseCount() {
136+
// const primaryLang = getLocalStorage('details-primary'); // 'JavaScript'
137+
// const selectedDataType = getLocalStorage('data-type'); // number
138+
// const method = getLocalStorage('method-selection'); // 1
139+
// const langObjMethod = languages[primaryLang][selectedDataType];
140+
// const typeObjects = detailsPre[primaryLang][selectedDataType];
141+
142+
// typeObjects.forEach(item => {
143+
// console.log(item.keywords); // each keywords array
144+
// })
145+
146+
// console.log(selectedDataType, method, langObjMethod[method]); // number 1 Math.max -> should be Math.min
147+
// console.log(typeObjects.length); // 7
148+
// }
149+
// getMthodUseCount()
150+
151+
function getMethodUseCount(methodName) {
152+
const primaryLang = getLocalStorage('details-primary');
153+
const selectedDataType = getLocalStorage('data-type');
154+
155+
const typeObjects = detailsPre[primaryLang][selectedDataType];
156+
157+
if (!typeObjects) return 0;
158+
159+
let count = 0;
160+
161+
typeObjects.forEach(item => {
162+
if (item.keywords.includes(methodName)) {
163+
count++;
164+
}
165+
});
166+
167+
return count;
136168
}
137-
getDataTypeLen()
138169

139170
/**
140171
* * FUNCTIONS FOR EVENT LISTENERS
@@ -178,7 +209,7 @@ function handlePrimaryCheck(e) {
178209
state.detailsPrimary = e.target.value;
179210
setLocalStorage('details-primary', state.detailsPrimary);
180211

181-
createOptions()
212+
// createOptions()
182213
}
183214

184215
// 3. Secondary language radio button check
@@ -215,7 +246,7 @@ function handleDetailsFormSubmit(e) {
215246
e.preventDefault();
216247

217248
setLocalStorage('type-selection', dataTypeSelect.selectedIndex);
218-
setLocalStorage('method-selection', methodsSelect.selectedIndex);
249+
setLocalStorage('method-selection', methodsSelect.value);
219250

220251
state.detailsPrimary
221252
const primaryDisplay = getLocalStorage('details-primary');

0 commit comments

Comments
 (0)