-
Notifications
You must be signed in to change notification settings - Fork 0
/
findMoodsByTag.js
77 lines (45 loc) · 1.44 KB
/
findMoodsByTag.js
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
//Instantiate contains method into string object
if (typeof String.prototype.contains === 'undefined') {
String.prototype.contains = function(it) {
return this.indexOf(it) != -1;
};
}
/*
var patt1=new RegExp(pattern,modifiers);
//or more simply:
var patt2=/pattern/modifiers;
pattern specifies the pattern of an expression
modifiers specify if a search should be global g, case-sensitive i, etc.
*/
var str = "Mr. Blue has a blue house";
var n = str.search(/blue/i);;
function findMoodsByTag(tagString) {
var moods = ["social"];
var s = "foo";
if(tagString.indexOf("bowling") != -1) {
console.log("tagString.indexOf('bowling') = " + "found");
moods = ["active"];
}
var ind = tagString.contains(/boling/i);
console.log("ind = " + ind);
if (tagString.contains(/boling/i) == true){
console.log("tagString.contains(/boling/i) ==" + ind);
moods = ["active"];
}
var srch = tagString.search(/bowling/i) ;
console.log("srch = " + srch);
if (tagString.search(/bowling/i) != -1){
console.log("tagString.search(/bowling/i) = " + "found");
moods = ["active"];
}
return moods;
}
/*
sporty - Live Sport ,
active - bowling
rich - shopping, retail
artistic - culture , art , festival
intelligent - speaker
*/
var tags = "bowling, music, diner, cocktails, pop-up";
console.log("moods for tag:" + tags+ " = " + findMoodsByTag(tags))