-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcoding_challenge.js
More file actions
45 lines (39 loc) · 794 Bytes
/
coding_challenge.js
File metadata and controls
45 lines (39 loc) · 794 Bytes
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
/**
* input: cat, car, bar
*
* function setup(input)
*
* function isInDict(word)
*
* setup("cat", "car", "bar");
* isInDict("cat"); // true
* isInDict("bat"); // false
*/
class Dictionary {
constructor(input) {
this.wordsArray = input || [];
this.dict = null;
}
setup() {
this.dict = new Set(this.wordsArray);
}
isInDict(word) {
return this.dict.has(word);
}
}
class Solution {
constructor(input) {
this.inputArray = input || [];
}
logger(word) {
const dict = new Dictionary(this.inputArray);
dict.setup();
const result = dict.isInDict(word);
console.log('result: ', result);
return;
}
}
const solution = new Solution(["cat", "car", "bar"]);
solution.logger('car');
solution.logger('cat');
solution.logger('bat');