// 封装indexOf(两个值,第一个数组,第二个要查找的内容,第三个值是从哪里开始找)
var arr = ["w","e","g","f","g"];
function fingIndex( array, con, star){
isNaN(star)? i = 0 : i =star;
for ( i; i < array.length; i++){
if( array[i] == con){
return i;
} //循环去判断
}return -1;
}console.log( fingIndex(arr,"g",''))//2
封装一个reverse函数
var arr = [1, 4, 5, 6, 7, 7, 9];
function isArray (array){
var b = []
var len = array.lenght
if( array instanceof Array){ //要求判断参数是否是数组
for ( i = 0; i < len; i++){
b.unshift(arr[i])
}
}else{
console.log("请输入一个正确的数组")
}
}
console.log (isArray(arr))
冒泡排序(从大道小)
function maopao(arr){
var len = arr.length;
for (var i = 0; i < len - 1; i++) {
for(var j = 0;j < len - 1 - i; j++){
if (arr[j] > arr[j+1]) {
var num = arr[j];
arr[j] = arr[j+1];
arr[j+1] = num
}
}
}
return arr
}
console.log(maopao(arr))