-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathwords-utility.js
More file actions
153 lines (82 loc) · 3.07 KB
/
words-utility.js
File metadata and controls
153 lines (82 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//var theWords = "A Unit Test is a piece of code that is using your code, exercising some scenarios that it expects to work in a certain way. Unit tests are isolated from external dependencies unlike integration tests. We will focus on Unit Tests.";
WordsUtility = function(words){
this.countWords = function(){
var numberOfWords= words.split(" ").length;
return words.split(" ").length;
}
this.longestWord = function(){
// describe step one
// describe step two
// describe step three
// return the longest word
var longWord = "";
var wordCollection=words.split(" ");
for(i =0; i < wordCollection.length; i++){
if(longWord.length < wordCollection[i].length){
longWord = wordCollection[i];
}
}
return longWord
//return "dependencies";
}
this.averageWordLength= function(){
var numberOfWords= words.split(" ").length;
var wordCollection=words.split(" ");
//go to each word and find it's length
// add this length to a variable initialized out side of the loop - totalLength for example
//once done divide totalLength with numberOfWords
var totalLength=wordCollection.join("+").length;
for(i=0;i<1;i++){
return totalLength/ numberOfWords
}
}
this.wordsWithTheSameLength= function(){
var wordCollection=words.split(" ");
var SameLength={};
for(i=0;i<wordCollection.length;i++){
var Lang = wordCollection[i].toLowerCase();
if(!SameLength[Lang.length]){
SameLength[Lang.length]=[];
}
SameLength[Lang.length].push(Lang);
}
return SameLength;
}
this.shortestWord= function(){
var wordCollection=words.split(" ");
var shortWord = wordCollection[wordCollection.length-1];
for(i =0; i < wordCollection.length; i++){
if(shortWord.length > wordCollection[i].length){
shortWord = wordCollection[i];
}
}
return shortWord;
}
this.mostWordsEndWith= function(){
var wordCollection=words.split(" ");
var EndWith={};
for(i=0;i<wordCollection.length;i++){
var letter=wordCollection[i].charAt(wordCollection[i].length-1).toLowerCase();
if(letter==="."||letter==","){
letter=wordCollection[i].charAt(wordCollection[i].length-2).toLowerCase();
}
if(!EndWith[letter]){
EndWith[letter]=[];
}
EndWith[letter].push(letter);
}
return letter
}
this.mostWordsStartWith= function(){
var wordCollection=words.split(" ");
var StartWith={};
for(i=0;i<wordCollection.length;i++){
var letter=wordCollection[i][0].toLowerCase();
if(!StartWith[letter]){
StartWith[letter]=[];
}
StartWith[letter].push(wordCollection[i]);
}
return letter;
}
}