var a=[1,6,3,8,5],b=[2,9,4,7,10];实现一个不用数组便捷方法的 数组合并和冒泡排序:
平时肯定想到的是 扩展运算符和sort()方法
面试官想考的地方: for循环进行下标的赋值,原生数组排序
使用for
let arr = []
for(let i=0;i<a.length;i++){
arr[i] = a[i]
}
for(i=0,i<arr.length,i++){
for(j=0,i<arr.length - i -1,j++){
if(arr[j]>arr[j+1]){
let temp = arr[i]
arr[i] = arr[j+1]
arr[j+1] = temp
}
}
}
延申快排:
function quicksort(arr){
if(arr,length<=1){return arr}
var privotIndex = Math.floor(arr.length/2)
//找出中间的值
var centerData = arr.splice(privotIndex ,1)[0]
//定义左右数组
var left = [];var right = [];
for(var i = 0;i<arr.length;i++){
if(arr[i]<= privot){
left.push(arr[i])}
else{
right.push(arr[i])
}
}
//递归
return quickSort(left),concat([centerData],quickSort(right))
}
js 继承的理解
原型链的继承
父:function Person(name){
this.name = name;
this.sum=function(){
alert('this.name',this.name)
}
}
Person.prototype.age = 100
function child(){
this.name="xiaoming"
}
child.prototype = new Person()
let child1 = new Child()
child1.name //xiaoming
child1.age //100
child1 instanceof Person //true
table 里的某个值