I was attending today’s headlines the front end of the written examination, feeling cool, seem to still want to know both sides, the next time you want to preview the other party’s pen test questions, memories begin with the last question, I try to recall, all want to be able to help people, I also want to add supplements the data structure, algorithm of knowledge, has knowledge of network communication. The last question has 5 choices: The first one is about pushing and unpushing:

A 41 B 42 C 43 D 44 A 41 B 42 C 43 D 44Copy the code

A face meng force, do not understand, the front end will encounter this kind of problem, worthy of being a big company, is not the same. The second problem is about sorting algorithms, time complexity

Which of the following algorithms has a time complexity less than nlogn a quick sort b bubble sort c merge sort d heap sortCopy the code

Do not understand, or computer major good. There is also about network communication

TCP and UDP difference, this topic accounted for two questions oh.Copy the code

Baidu:

TCP/IP is a protocol group that can be divided into three layers: the network layer, the transport layer, and the application layer. At the network layer, there are IP, ICMP, ARP, RARP, and BOOTP protocols. There are TCP and UDP protocols at the transport layer. Protocols at the application layer include FTP, HTTP, TELNET, SMTP, and DNS. Therefore, HTTP is itself a protocol, a transport protocol for transferring hypertext from a Web server to a local browser. 2. The HTTP protocol is based on the request/response model. The client establishes a TCP connection to the server and sends a request to the server containing the request method, URI, protocol version, and associated MIME style message. The server responds with a status line containing the protocol version of the message, a success and failure code, and the associated MIME style of the message. HTTP/1.0 establishes a new TCP link for each HTTP request/response, so a page containing HTML content and images will need to establish multiple short-term TCP links. A TCP connection will require three handshakes. In addition, additional loop connection time (RTT) is required for TCP to obtain the appropriate transmission speed. This overhead is required for each link to be created, with no actual useful data, just to ensure the reliability of the link, so HTTP/1.1 proposed the implementation of sustainable links. HTTP/1.1 will establish only one TCP link and use it repeatedly to transmit a series of request/response messages, thus reducing the number of link establishment and recurrent link overhead. Conclusion: Although HTTP is a protocol in itself, it is ultimately based on TCP. However, at present, some people are studying HTTP protocol based on TCP+UDP hybrid. What is a Socket? Socket is the intermediate software abstraction layer of communication between application layer and TCP/IP protocol family. It is a group of interfaces. In the design mode, Socket is actually a facade mode, it hides the complex TCP/IP protocol family behind the Socket interface, for the user, a simple set of interfaces is all, let the Socket to organize data to conform to the specified protocol. HTTP, TCP, UDP, and Socket < WBR > < WBR > < WBR > < WBR > < WBR > HTTP: application layer protocol; SOCKET: TCP/IP network API. TCP/IP stands for Transmission Control Protocol/Internet Protocol and refers to a series of protocols. TCP and UDP use the IP protocol to send packets from one network to another. Think of IP as a kind of highway that allows other protocols to travel on and find exits to other computers. TCP and UDP are the "trucks" on the highway, carrying the cargo of protocols like HTTP, FILE transfer protocol FTP, etc. TCP and UDP are transport layer protocols used by FTP, HTTP, and SMTP. Although both TCP and UDP are used to transport other protocols, they have one significant difference: TCP provides guaranteed data transfer, while UDP does not. This means that TCP has a special mechanism to ensure that data passes safely and error-free from one endpoint to another, whereas UDP does not provide any such guarantees. HTTP(Hypertext Transfer Protocol) is a protocol that uses TCP to transfer information between two computers, typically a Web server and a client. The client sends an HTTP request to the Web server using a Web browser, and the Web server sends the requested information to the client. Remember, you need IP to connect to the network; TCP is a mechanism that allows us to transfer data securely. HTTP, which uses TCP to transfer data, is a special protocol used by Web servers and clients. The Socket interface is an API of the TCP/IP network. The Socket interface defines many functions or routines for developing applications on the TCP/IP network. The network is divided into physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer from bottom to top. IP protocol corresponds to the network layer, TCP protocol corresponds to the transport layer, AND HTTP protocol corresponds to the application layer. In essence, the three are not comparable. Socket is the encapsulation and application of TCP/IP protocol. Socket is the encapsulation of TCP/IP. Socket itself is not a protocol, but a call interface (API). Through the socket, We can use TCP/IP. In fact, sockets are not necessarily related to TCP/IP. When Socket programming interface is designed, it is hoped that it can also adapt to other network protocols. Therefore, the Socket is just a convenient way for programmers to use TCP/IP stack. It is an abstraction of TCP/IP protocol, and forms some of the most basic function interfaces that we know, such as CREATE, LISTEN, connect, Accept, send,readIn fact, TCP at the transport layer is based on IP at the network layer, while HTTP at the application layer is based on TCP at the transport layer. The Socket itself is not a protocol. As mentioned above, it only provides a three-way handshake for TCP or UDP programming interfaces: First handshake: The client sends a SYN packet (SYN = J) to the server and enters the SYN_SEND state. Second handshake: After receiving a SYN packet, the server must acknowledge the client's SYN (ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state. Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state to complete the three-way handshake. The packet transmitted during the handshake does not contain data. Data is transmitted between the client and server only after the three-way handshake is complete. Both the server and client can initiate a request to disconnect the TCP connection. Although the insecure and unstable characteristics of the network determine how many handshakes can not guarantee the reliability of the connection, but TCP three handshakes in the minimum (in fact, also to a large extent) to ensure the reliability of the connection; UDP is not connection-oriented, UDP does not establish a connection with the other party before transmitting data, docking received data does not send confirmation signal, the sender does not know whether the data will be correctly received, of course, also do not have to resend, so UDP is connectionless, unreliable data transmission protocol is also due to the above characteristics, UDP has a lower overhead and a higher data transfer rate. UDP provides better real-time performance because there is no need to confirm whether to send or receive data. Therefore, MSN using TCP transfer protocol is slower than QQ using UDP, but it does not say that QQ communication is not secure, because the programmer can manually verify the UDP data sent and received, such as the sender of each packet number and then verified by the receiver ah, even so, UDP achieves the transmission efficiency that TCP cannot achieve because it does not adopt the "three-way handshake" similar to TCP in the encapsulation of the underlying protocol.Copy the code

Another one is about the HTTP protocol

I don't remember what the questions are, but I can give you a general description of what the test is about, is HTTP correct, GET, POST, etc.Copy the code

That’s probably what the multiple choice questions look like. Very basic, is not understanding of the lead, but really can not answer. Yeah, well, I guess I’m gonna have to work on my basics.

Next is an algorithm, also very basic, I chose to write in javascript language

Find out the input n number, find out the frequency of the number greater than n/2 to find the answer of the user#include <iostream>
#include <vector>using namespace std; Int find_data(vector<int> &arry) {int ntime = 0; // The number of occurrences of one of these numbers int result;for(unsigned int i = 0; i < arry.size(); i++) {
        if(ntime == 0) {result = arry[I]; (ntime == 0) {result = arry[I]; ntime = 1; //arry[I] = 1; }else{// if this is the case, the result is not completely cancelled outif(result == arry[I]) // If result == arry[I])elsentime--; /* if arry[I] is not equal to result, then they cancel out. If arry[I] is not equal to result, then they cancel out. If arry[I] is not equal to result, then they cancel out.return result;
}
int main()
{
    vector<int> arry; 
    int n;
    cin>>n;
    for(int i = 0; i < n; i++) {
            int d;
        cin>>d;
        arry.push_back(d);
    }
    int result = find_data(arry);
    cout<<result;
    return 0;
}
Copy the code

So the first one is the closure, the this object points to the problem

var inner = "window";
function say(){
	console.log(inner);
	console.log(this.inner);
}
var obj1 = (function(){
	var inner = 1-1 ' ';
	return {
		inner: "1-2",
		say: function(){
			console.log(inner);
			console.log(this.inner);
		}
	}
})()
var obj2 = (function(){
	var inner = '2-1';
	return {
		inner: "2-2",
		say: function(){
			console.log(inner);
			console.log(this.inner);
		}
	}
})()

say();
obj1.say();
obj1.say = say;

obj1.say = obj2.say;
obj1.say();
Copy the code

Print it out or

window
window
1-1
1-2
2-1
1-2
Copy the code

Okay, so the next problem is to modify the program

Log (1) console.log(2) console.log(3) console.log(4) console.log(5) console.log(6) console.log(7) Log (8) console.log(9) var arr = [];for(var i=0; i<10; i++){ var fn =function(){
		console.log(i);
	}
	arr.push(fn);
}
arr.forEach(function(fn){
	fn()
})
Copy the code

My revised answer is as follows:

Plan 1for(leti=0; i<10; i++){ var fn =function(){ console.log(i); } arr.push(fn); 2} schemefor(var i=0; i<10; i++){ var fn = (function(){ console.log(i); })(i) arr.push(fn); } solution 3for (var i = 0; i < 10; i++) {
    arr[i] = (function(c) {
        return function(){
            console.log(c);
        }
    })(i);
}
Copy the code

There is also a problem is: about the algorithm

Find an array in which the number of occurrences of elements is greater than N /2, and return the array of these elements. Public class NumCountGTHalfLen {public static void main(String[] args) {int[] ,2,3,2,5,6,2,2,3,2,2,4,2 arr = {1}; / / 2 / / int [] arr =,2,3,3,3,6 {2}; / / int [] arr = {1, 2, 3}; / / int [] arr =,1,2,2 {1}; int n = numCountGTHalfLen(arr); System.out.println(n); } private static int numCountGTHalfLen(int[] arr) { int count = 1; int num = arr[0];for (int i = 1; i < arr.length; i++) {
            if (count == 0){
                count = 1;
                num = arr[i];
            }else {
                if (arr[i]==num){
                    count++;
                }else{ count--; Count = 0; count = 0;for (int i : arr) {
            if (i == num) count ++;
        }
        returncount > arr.length/2 ? num : 0; }}Copy the code

Javascript interview questions – the variety of ways to find out the highest frequency of the array elements blog.csdn.net/u011277123/… There’s another problem like this

Array.prototype.finddup = array.prototype.finddUp = array.prototype.finddUp = array.prototype.finddUp =function (count) {
  return this.reduce((re, val) => {
    let index = re.findIndex(o => o.val === val)
    if (index >= 0) {
      re[index].count++
    } else {
      re.push({ count: 1, val })
    }
    returnRe}, []).filter(o => O.count >= count).map(o => O.val)function(arr){
  return (n)=>{
    if(isNaN(n))return [];
    n = n < 1 ? 1 : n
    let resulte = [],
      obj = Object.create(null)
    arr.forEach(item=>{
      obj[ item ] = (obj[ item ] || 0) + 1
      if(obj[ item ] == n){
        resulte.push(item)
      }
    })
    returnFindDuplicate,2,3,4,1,2,2,2 resulte}} ([1]) (2) / / [1, 2] findDuplicate (5) / / [] findDuplicate (1) / / [1, 2, 3, 4]if(! Array.prototype.findDuplicate) { Object.defineProperty(Array.prototype,'findDuplicate', {
        value: function (n) {
            if (this === void 0 || this === null) {
                throw new TypeError('this is null or not defined');
            };
            var t = Object(this);
            var len = t.length >>> 0;
            var obj = {};
            var result = [];
            for(let i = 0; i < len; i++) {
                obj[t[i]] = (obj[t[i]] || 0)+1;
                if(obj[t[i]] == n) { result.push(t[i]); }}returnresult; }}); }Copy the code

Each net friend is the great god ah summarized here today, tomorrow to study these topics, a good supplement nutrition.