-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
92 lines (82 loc) · 1.47 KB
/
test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var oddsAndEvens = function(arr){
var oCount = 0;
var eCount = 0;
for(var i=0;i<arr.length;i++){
if(arr[i]%2==0){
eCount++;
oCount=0;
}
else{
oCount++;
eCount=0;
};
if(eCount>=3){
console.log("EVEN!")
};
if(oCount>=3){
console.log("ODD!")
};
}
}
var evensAndOdds = function(arr){
for(var i=0;i<arr.length;i++){
if(i<arr.length-2){
if(arr[i]%2==0 && arr[i+1]%2==0 && arr[i+2]%2==0){
console.log("Even more so!");
};
if(arr[i]%2!=0 && arr[i+1]%2!=0 && arr[i+2]%2!=0){
console.log("Thats odd!");
};
};
};
};
// var eval = "("
// switch(eval){
// case "a":
// var hello = "a";
// console.log("in a");
// break;
// case "b":
// var hello = "b";
// console.log("in b");
// break;
// case "(":
// var hello = "(";
// console.log("in (");
// break;
// default:
// console.log("in default..");
// var hello = "default"
// break;
// }
// console.log(hello)
var strEncode = function(str){
str += ' ';
var newStr = "";
for(var i=0;i<str.length;i++){
if(!current){
var current = str[i];
var currentCount = 1;
}
if(str[i] != current){
switch(currentCount){
case 1:
newStr += current;
break;
case 2:
newStr += current + current;
break;
default:
newStr += currentCount.toString();
newStr += current;
break;
}
current = str[i];
currentCount = 1;
continue;
}
currentCount++;
}
return newStr;
}
//console.log(strEncode("aaaabbbbcccccddeee"))