Skip to content

Commit 0b2812f

Browse files
committed
modified
1 parent ceef5ba commit 0b2812f

File tree

2 files changed

+113
-5
lines changed

2 files changed

+113
-5
lines changed

JavaScript/carousel-js/js/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
newLeft = parseInt(current)-400;
2323
}
2424
wrap.style.left = newLeft + "px";
25-
//console.log("当前left "+wrap.style.left);
2625

2726
}
2827
function prev_pic(){
@@ -40,7 +39,6 @@
4039
newLeft = parseInt(current)+400;
4140
}
4241
wrap.style.left = newLeft + "px";
43-
//console.log("当前left "+wrap.style.left);
4442
}
4543

4644

@@ -78,13 +76,11 @@
7876
var current = getComputedStyle(wrap,false)["left"],
7977
newLeft;
8078
var currentLeft = parseInt(current);
81-
//console.log(index+" "+currentLeft);
79+
8280
if(index ==3 && currentLeft!==-1600){
83-
//console.log("chuxian1 "+currentLeft);
8481
gap = gap - 4;
8582
}
8683
if(index == 0 && currentLeft!==-400){
87-
//console.log("chuxian2 "+currentLeft);
8884
gap = 4 + gap;
8985
}
9086
wrap.style.left = (currentLeft + gap*400)+"px";

mixed-programming.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
/**************输出重复次数最多的字符********************/
3+
var str = 'assssjdssskssalsssdkjsssdss';
4+
5+
var arr = str.split(''); //把字符串转换为数组
6+
str = arr.sort().join(''); //首先进行排序,这样结果会把相同的字符放在一起,然后再转换为字符串
7+
//alert(str); // aaddjjkklsssssssssssssssss
8+
9+
var value = '';
10+
var index = 0;
11+
var re = /(\w)\1+/g; //匹配字符,且重复这个字符,重复次数至少一次。
12+
str.replace(re,function($0,$1){
13+
console.log($0); //代表每次匹配成功的结果 : aa dd jj kk l sssssssssssssssss
14+
//alert($1); 代表每次匹配成功的第一个子项,也就是\w: a d j k l S
15+
  
16+
if(index<$0.length){ //如果index保存的值小于$0的长度就进行下面的操作
17+
index = $0.length; // 这样index一直保存的就在最大的长度
18+
value = $1; //value保存的是出现最多的这个字符
19+
}
20+
21+
});
22+
23+
console.log('最多的字符:'+value+',重复的次数:'+index); // s 17
24+
25+
/***********************输出最先出现3次的字母*******************************/
26+
27+
var line = "Have you ever gone shopping and",
28+
o = {},
29+
str = line.replace(/\s/ig,'');
30+
for (var i=0; i<str.length; i++){
31+
var char = str.charAt(i);
32+
if(!o[char]){
33+
o[char]=1;
34+
}else{
35+
o[char]++;
36+
if(o[char]==3 && /\w/.test(char)){
37+
console.log(char);
38+
break;
39+
}
40+
}
41+
}
42+
43+
/*************************去掉一个最小的数字,剩下的组成最大数*****************************/
44+
var num;
45+
46+
function minNum(str){
47+
var index,
48+
tmp=parseInt(str.charAt(0));
49+
for(var i=1; i<str.length; i++){
50+
if(parseInt(str.charAt(i)) <= tmp){
51+
index = i;
52+
}
53+
}
54+
str = str.substring(0,index) + str.substring(index+1,str.length);
55+
console.log(str);
56+
return str;
57+
}
58+
59+
for(var j=0; j<1; j++){
60+
num = minNum("325");
61+
}
62+
console.log(num);
63+
64+
/********************二分查找***********************/
65+
//非递归
66+
function binary_search(arr, key){
67+
var low = 0,
68+
high = arr.length - 1;
69+
while(high >= low){
70+
var mid = parseInt((high+low)/2);
71+
if(key == arr[mid]){
72+
return mid;
73+
}
74+
else if(key > arr[mid]){
75+
low = mid + 1;
76+
}
77+
else id(key < arr[mid]){
78+
high = mid - 1;
79+
}
80+
else{
81+
return -1;
82+
}
83+
}
84+
}
85+
//递归
86+
function binary_search(arr,low, high, key) {
87+
if (low > high){
88+
return -1;
89+
}
90+
var mid = parseInt((high + low) / 2);
91+
if(arr[mid] == key){
92+
return mid;
93+
}else if (arr[mid] > key){
94+
high = mid - 1;
95+
return binary_search(arr, low, high, key);
96+
}else if (arr[mid] < key){
97+
low = mid + 1;
98+
return binary_search(arr, low, high, key);
99+
}
100+
};
101+
102+
function A(){
103+
var i = 0;
104+
return function(){
105+
console.log(i++);
106+
}
107+
}
108+
var f1 = new A(),
109+
f2 = new A();
110+
f1();
111+
f1();
112+
f2();

0 commit comments

Comments
 (0)