Coding
- Merges two ordered arrays and computes the median number
/ / m,2,4,5,6,8,11 [1]
/ /,5,6,8,10 [2] n
// 1. If there are even numbers, take the average of the two middle numbers
// 2. The time complexity cannot exceed O(m+n).
function merge(arr1, arr2) {
let newArr = [];
let i=0;
let j=0;
// Add in order
while(i ! == arr1.length && j ! == arr2.length) {if (arr1[i] < arr2[j]) {
newArr.push(arr1[i])
i++;
} else{ newArr.push(arr2[j]); j++; }}// Dispose of the unadded
while(i ! == arr1.length) { newArr.push(arr1[i]) i++; }while(j ! == arr2.length) { newArr.push(arr2[j]) j++; }// find the median
let len = i+j;
if(! (len %2)) {
return (newArr[len/2] + newArr[len/2 - 1) /2
} else {
return newArr[parseInt(len/2)]}}Copy the code
JS
- Prototype and prototype chain
What are the following three equal to
function foo(){}
const bar = new foo()
bar.__proto__ === foo.prototype
foo.__proto__ === Function.prototype
foo.prototype.constructor === foo
Copy the code
HTML/CSS
-
A div’s height of 100px is defined by its content. If you add the style height:50px; Overflow: Hidden, will backflow redraw be triggered? If it has the style position:absolute first, what will be triggered by adding the style above?
- The visible size of the element changes, so a backflow redraw occurs
- When it is absolutely positioned, away from the normal document flow, the width also becomes spread out by its contents, as can be seen that a change in size triggers a backflow redraw
-
What kinds of document flows are there
- Normal document flow
- Floating document flow
- Locating the document flow
-
There are ways to get out of the normal document flow
- floating
- Absolute positioning
- Fixed position