File tree 1 file changed +55
-0
lines changed
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -215,4 +215,59 @@ function weather() //weather fu
215
215
// console.log(howManyLetters(phrase))
216
216
217
217
218
+ // sumArray = (array) => //ARRAY ELEMENTS SUM
219
+ // {
220
+ // result =0
221
+
222
+ // for(i of array)
223
+ // result+= Number(i)
224
+ // return result
225
+ // }
226
+
227
+ // array = ['1','3','5','6']
228
+ // console.log(sumArray(array))
229
+
230
+ //ARRAY MAX ELEMENT
231
+
232
+
233
+ // const arrayFreq = (array) => //ARRAY ELEMENT FREQ
234
+ // {
235
+ // // letterFreq('haha' ) => {'h' :2 , 'a' : 2}
236
+
237
+ // console.log(array)
238
+
239
+ // let freq= {} //make freq object
240
+
241
+ // for(const letter of array)
242
+
243
+ // //check if letter exists in freq object
244
+ // if(letter in freq)
245
+ // freq[letter] = freq[letter] + 1 //if yes, increment by +1
246
+ // else
247
+ // freq[letter] = 1 //otherwise, set value to 1
248
+
249
+ // return freq
250
+ // }
251
+
252
+ // array='hahaha'
253
+ // console.log(arrayFreq(array))
254
+
255
+
256
+ const wordFreq = ( array ) =>
257
+ {
258
+ let freq = { }
259
+
260
+ words = array . split ( ' ' )
261
+ for ( const word of words )
262
+ {
263
+ if ( word in freq )
264
+ freq [ word ] += 1
265
+ else
266
+ freq [ word ] = 1
267
+ }
268
+
269
+ return freq
270
+ }
271
+
272
+ console . log ( wordFreq ( "hi, hi ishika ishika goyal" ) )
218
273
You can’t perform that action at this time.
0 commit comments