July 12
Questions
A question: whether the site Logo should appear in the <h1> tag?
Two questions: whether to support IE6?
Interview questions
What is the box model?
Answer:margin
,border
,padding
,content
; standard boxes and boxes weird? Description of the difference between the src and href
Answer: src introducing resources from outside, href page will guide external resourcesDescription of synchronous and asynchronous difference?
A: Synchronization: After the implementation of the current process, the next process to execute; asynchronous: the implementation of the current process does not affect the execution of a processHow to add, remove, move, copy, create, and find nodes?
A: add nodesappendChild
, remove nodesremoveChild
, copy nodesclone
, createcreateElement
, find nodesparentNode
,childNodes
Programming problem
Find the location of elements in a given item in the array arr
编程思路:二分查找
function indexOf(arr, item) {
var arr = arr.sort(function(a,b){
return a-b;
});
function binSearch(arr,item){
var upperBound = arr.length-1;
var lowerBound = 0;
while(lowerBound<=upperBound){
var mid = Math.floor((upperBound+lowerBound)/2);
if(arr[mid]<item){
lowerBound=mid+1;
}else if(arr[mid]>item){
upperBound=mid-1;
}else{
return mid;
}
}
return -1;
};
return binSearch(arr,item);
};
var line = readline();
var lastIndex = line.lastIndexOf(",");
var arr = line.slice(0,lastIndex).match(/\d/g);
var num = parseInt(line.slice(lastIndex+1));
indexOf(arr,num);
Calculating the sum of a given array containing all elements arr
编程思路:迭代器简化代码量
function sum(arr) {
function add(runningTotal,currentValue){
return runningTotal+currentValue;
}
return arr.reduce(add);
}
This article is reproduced in: ape 2048⇨ https://www.mk2048.com/blog/blog.php?id=ha1k2bj2h0j