@@ -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