File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ Given a text, find the frequency of all the words in it and print the words that are duplicates:
2
+ "Work hard and play hard and have fun at work."
3
+
4
+ answer:
5
+ hard
6
+ work
7
+ and
Original file line number Diff line number Diff line change
1
+ function printDuplicates ( inputText ) {
2
+ var frequenceCountMap = { } ;
3
+ var inputs = inputText . split ( ' ' ) ;
4
+ for ( var ii = 0 , len = inputs . length ; ii < len ; ii ++ ) {
5
+ var word = inputs [ ii ] ;
6
+ if ( frequenceCountMap [ word ] ) {
7
+ frequenceCountMap [ word ] += 1 ;
8
+ } else {
9
+ frequenceCountMap [ word ] = 1 ;
10
+ }
11
+ }
12
+
13
+ for ( var key in frequenceCountMap ) {
14
+ if ( frequenceCountMap [ key ] > 1 ) {
15
+ console . log ( key ) ;
16
+ }
17
+ }
18
+ }
19
+
20
+ var inputVal = "Work hard and play hard and have fun at work." ;
21
+
22
+ printDuplicates ( inputVal ) ;
You can’t perform that action at this time.
0 commit comments