Skip to content

Commit d785308

Browse files
committed
Added word frequency problem
1 parent ee0a282 commit d785308

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Word_Frequency/question.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

Word_Frequency/solution.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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);

0 commit comments

Comments
 (0)