面试题总结
面试题1:
1 let list = [ 2 { 3 name:'万仙', 4 age:20, 5 sex:"male" 6 }, 7 { 8 name:'凤凰', 9 age:10, 10 sex:"female" 11 }, 12 { 13 name:'桐柏', 14 age:28, 15 sex:"male" 16 }, 17 { 18 name:'云台', 19 age:18, 20 sex:"female" 21 } 22 ] 23 24 function compress(collection = []){ 25 let keyval = Object.keys(collection[0]) 26 // console.log(keyval); 27 let res = collection.map(item => { 28 let val = [] 29 for(let key in item){ 30 val.push(item[key]) 31 } 32 return val; 33 }) 34 return [keyval, ...res] 35 } 36 37 console.log(compress(list)); 38
面试题2:
实现合并两个数组并去重
function concat(a, b){
}
1 // ============== es6 方式 2 // function concat(a, b){ 3 // return [...new Set([...a, ...b])] 4 // } 5 6 // ============ 常规方式 7 function concat(a, b){ 8 let newArr = a.concat(b); 9 let result = []; 10 for(let i = 0; i < newArr.length; i++){ 11 if(result.indexOf(newArr[i]) == -1){ 12 result.push(newArr[i]) 13 } 14 } 15 return result; 16 } 17 18 let res = concat([1, 2, 3, 4], [2, 3, 4, 5]) 19 console.log(res);
笔试题3:
1 let arr = [12, 34, 657, 23]; 2 // 对数组进行排序 3 // arr.sort(function(x, y){ 4 // return x - y; 5 // }) 6 // let diff = arr[0] - arr[arr.length - 1] 7 8 9 // =========== 求数组中的最大值 和最小值 10 // let max = Math.max.apply(null, arr); 11 // let min = Math.min.apply(null, arr); 12 // let diff = max - min; 13 // console.log(diff); 14 15 16 // =============== 遍历 17 // let max = arr[0], min = arr[0]; 18 // for(let i = 0; i < arr.length; i++){ 19 // if(max < arr[i]){ 20 // max = arr[i] 21 // } 22 // if(min > arr[i]){ 23 // min = arr[i] 24 // } 25 // } 26 // console.log(max - min);
笔试题4
解决谷歌浏览器字体大小小于12px方法
1 .small{ 2 transform:sale()//缩放字体 用缩放解决小于12px的问题