1.添加css样式,使content垂直居中
方法1:1
2
3
4
5
6
7
8
9
10
11
12
13
14.container{
width: 200px;
height: 200px;
background: red;
position:relative;
}
.content{
width: 50px;
height: 50px;
background: blue;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
方法2:1
2
3
4
5
6
7
8
9
10
11
12
13
14.container{
width: 200px;
height: 200px;
background: red;
display:table-cell;
vertical-align:middle;
text-align: center;
}
.content{
width: 50px;
height: 50px;
background: blue;
display:inline-block;
}
方法3:(不太兼容)1
2
3
4
5
6
7
8
9
10
11
12
13.container{
width: 200px;
height: 200px;
background: red;
display:flex;
justify-content:center;//ie11
align-items:center;//ie11
}
.content{
width: 50px;
height: 50px;
background: blue;
}
方法4:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16.container{
width: 200px;
height: 200px;
background: red;
position: relative;
}
.content{
width: 50px;
height: 50px;
background: blue;
position: absolute;
left: 50%;
margin-left: -25px;
top: 50%;
margin-top: -25px;
}
2.创建一个长度为100的数组,其中每一项的值都为11
2
3
4
5
6
7<script type="text/javascript">
var arr = [];
for (var i = 0; i < 100; i++) {
arr.push(1);
}
alert(arr);
</script>
3.以下端口是用来做什么服务的或则用的什么协议
80端口:
443端口:
22端口:
1080端口:
4.深拷贝和浅拷贝的区别
首先深复制和浅复制只针对像 Object, Array 这样的复杂对象的。简单来说,浅复制只复制一层对象的属性,而深复制则递归复制了所有层级。
5.假设两个字符串中所含有的字符和个数都相同我们就叫这两个字符串匹配, 比如:abcda 和 adabc,由于出现的字符个数都是相同,只是顺序不同, 所以这两个字符串是匹配的。要求高效!
a.轮询难度系数o(i*j)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<script type="text/javascript">
var num1= 'abcda',
num2 = 'adabc',
i,
j;
//判断num1和num2字符串的长度关系,长度较短的应该在最外层for循环里,如果长度相等则都可以
if (num1.length < num2.length) {
for (i = 0; i < num1.length; i++) {
for (j = 0; j < num2.length; j++) {
if (num1[i] == num2[j]) {
break;
}
}
if (j == num2.length) {
alert(false);
}
}
alert(true);
}
else{
for (i = 0; i < num2.length; i++) {
for (j = 0; j < num1.length; j++) {
if (num2[i] == num1[j]) {
break;
}
}
if (j == num1.length) {
alert(false);
}
}
alert(true);
}
</script>
6.给你一个getIntersection方法要实现一下效果1
2
3
4
5
6
7
8
9function getIntersection(...args) {
your code~
}
getIntersection([1, 4], [3, 5]); // return [ 3, 4 ]
getIntersection([5, 2], [4, 9], [3, 6]); // return [ 4, 5 ]
getIntersection([1, 7], [8, 9]); // return null
getIntersection(['x', 7], [4, 9]); // return null
getIntersection([1, 2]); // return [ 1, 2 ]
getIntersection([1, 2], [2, 3]); // return [ 2, 2 ]
渣渣写法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
54function getIntersection(...args) {
var array = null;
if(args.length == 1){
return args;
}
else{
Array.prototype.getAnd = function(arr){
var newArr = [];
function sortNum(a,b){
if(typeof a == Number && typeof b == Number){
return null;
}
else{
return a-b;
}
}
this.sort(sortNum);
arr.sort(sortNum);
if(!(this instanceof Array) || !(arr instanceof Array)){
return null;
}
else{
var a = this[0];
var b = this[1];
if(a<=arr[0] && arr[1]<=b){
newArr = arr;
}
else if (a<=arr[0] && b>=arr[0] && arr[1]>=b) {
newArr.push(arr[0],b);
}
else if (a>=arr[0] && arr[1]>=a && arr[1]<=b) {
newArr.push(a,arr[1]);
}
else if(a>arr[0] && arr[1]>a && arr[1]>b){
newArr = this;
}
}
if (newArr.length == 2) {
return newArr;
}
else{
return null;
}
}
array = args[0].getAnd(args[1]);
for (var i = 2; i < args.length; i++) {
array = array.getAnd(args[i]);
}
}
return array;
}