Skip to content

Commit 3e50904

Browse files
MohdImran001Shinigami92
authored andcommitted
refactor: word.ts with requested changes
1 parent ffe3186 commit 3e50904

1 file changed

Lines changed: 35 additions & 47 deletions

File tree

src/word.ts

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ export class Word {
1616
* If specified length is unresolvable, returns random adjective.
1717
*
1818
* @method faker.word.adjective
19-
* @param {number} [length] - optional length of word to return
20-
* @returns {string} a random adjective
19+
* @param optional length of word to return
20+
* @returns a random adjective
2121
*/
2222
adjective(length?: number): string {
2323
var wordList = this.faker.definitions.word.adjective;
2424
if (length) {
25-
wordList = this.faker.definitions.word.adjective.filter(function (
26-
word: string
27-
) {
28-
return word.length == length;
29-
});
25+
wordList = this.faker.definitions.word.adjective.filter(
26+
(word: string) => word.length == length
27+
);
3028
}
3129

3230
// If result of filtered word list is undefined, return an element
@@ -42,15 +40,15 @@ export class Word {
4240
* If specified length is unresolvable, returns random adverb.
4341
*
4442
* @method faker.word.adverb
45-
* @param {number} [length] - optional length of word to return
46-
* @returns {string} random adverb
43+
* @param optional length of word to return
44+
* @returns random adverb
4745
*/
4846
adverb(length?: number): string {
4947
var wordList = this.faker.definitions.word.adverb;
5048
if (length) {
51-
wordList = this.faker.definitions.word.adverb.filter(function (word) {
52-
return word.length == length;
53-
});
49+
wordList = this.faker.definitions.word.adverb.filter(
50+
(word: string) => word.length == length
51+
);
5452
}
5553
// If result of filtered word list is undefined, return an element
5654
// from the unfiltered list.
@@ -65,17 +63,15 @@ export class Word {
6563
* If specified length is unresolvable, returns random conjunction.
6664
*
6765
* @method faker.word.conjunction
68-
* @param {number} [length] - optional length of word to return
69-
* @returns {string} random conjunction
66+
* @param optional length of word to return
67+
* @returns random conjunction
7068
*/
7169
conjunction(length?: number): string {
7270
var wordList = this.faker.definitions.word.conjunction;
7371
if (length) {
74-
wordList = this.faker.definitions.word.conjunction.filter(function (
75-
word: string
76-
) {
77-
return word.length == length;
78-
});
72+
wordList = this.faker.definitions.word.conjunction.filter(
73+
(word: string) => word.length == length
74+
);
7975
}
8076
// If result of filtered word list is undefined, return an element
8177
// from the unfiltered list.
@@ -89,17 +85,15 @@ export class Word {
8985
* If specified length is unresolvable, returns random interjection.
9086
*
9187
* @method faker.word.interjection
92-
* @param {number} [length] - optional length of word to return
93-
* @returns {string} random interjection
88+
* @param optional length of word to return
89+
* @returns random interjection
9490
*/
9591
interjection(length?: number): string {
9692
var wordList = this.faker.definitions.word.interjection;
9793
if (length) {
98-
wordList = this.faker.definitions.word.interjection.filter(function (
99-
word: string
100-
) {
101-
return word.length == length;
102-
});
94+
wordList = this.faker.definitions.word.interjection.filter(
95+
(word: string) => word.length == length
96+
);
10397
}
10498
// If result of filtered word list is undefined, return an element
10599
// from the unfiltered list.
@@ -113,17 +107,15 @@ export class Word {
113107
* If specified length is unresolvable, returns random noun.
114108
*
115109
* @method faker.word.noun
116-
* @param {number} [length] - optional length of word to return
117-
* @returns {string} random noun
110+
* @param optional length of word to return
111+
* @returns random noun
118112
*/
119113
noun(length?: number): string {
120114
var wordList = this.faker.definitions.word.noun;
121115
if (length) {
122-
wordList = this.faker.definitions.word.noun.filter(function (
123-
word: string
124-
) {
125-
return word.length == length;
126-
});
116+
wordList = this.faker.definitions.word.noun.filter(
117+
(word: string) => word.length == length
118+
);
127119
}
128120
// If result of filtered word list is undefined, return an element
129121
// from the unfiltered list.
@@ -137,17 +129,15 @@ export class Word {
137129
* If specified length is unresolvable, returns random preposition.
138130
*
139131
* @method faker.word.preposition
140-
* @param {number} [length] - optional length of word to return
141-
* @returns {string} random preposition
132+
* @param optional length of word to return
133+
* @returns random preposition
142134
*/
143135
preposition(length?: number): string {
144136
var wordList = this.faker.definitions.word.preposition;
145137
if (length) {
146-
wordList = this.faker.definitions.word.preposition.filter(function (
147-
word: string
148-
) {
149-
return word.length == length;
150-
});
138+
wordList = this.faker.definitions.word.preposition.filter(
139+
(word: string) => word.length == length
140+
);
151141
}
152142
// If result of filtered word list is undefined, return an element
153143
// from the unfiltered list.
@@ -161,17 +151,15 @@ export class Word {
161151
* If specified length is unresolvable, returns random verb.
162152
*
163153
* @method faker.word.verb
164-
* @param {number} [length] - optional length of word to return
165-
* @returns {string} random verb
154+
* @param optional length of word to return
155+
* @returns random verb
166156
*/
167157
verb(length?: number): string {
168158
var wordList = this.faker.definitions.word.verb;
169159
if (length) {
170-
wordList = this.faker.definitions.word.verb.filter(function (
171-
word: string
172-
) {
173-
return word.length == length;
174-
});
160+
wordList = this.faker.definitions.word.verb.filter(
161+
(word: string) => word.length == length
162+
);
175163
}
176164
// If result of filtered word list is undefined, return an element
177165
// from the unfiltered list.

0 commit comments

Comments
 (0)