The days are passing fast, laugh too, cry too, laugh also have to knock code, cry also have to knock code, then we do not laugh to knock code, some people see the code head is big, that is they did not put the code position, we have to learn self-regulation, we can think of the code as a delicious dish, to slowly taste, nasty, Urgent can not eat his delicious, code is the same, anxious you prone to error, but also can not taste the fun. Just like today I know the bubble sort method, how to let oneself more profound remember this method, we imagine is 10 beautiful woman standing in front of you, want you according to their height from left or right line, said beauty all have spirit, that how row, if from left to right, from low to high rank. Then you should compare the previous one with the latter one, if the previous one is higher than the last one, then the 22 exchange, so that the final row is from left to right, from low to high in order.
Today I also understand the function, know his function, characteristics. function is characterized by the reduction of garbage code, it has some duplicate code encapsulation, you think, if you repeatedly let the program run 1000 lines of code, and another we write the 1000 lines of code as a function, so that the program executes only one function, that more efficient, it is obvious that the second efficiency is better, The function has a fixed format: function name (argument list) {function body (code to be executed repeatedly)}, where function represents the functions, and He has three elements: functions name, parameter, return value. Note: The parameters are not required, some functions are not parameters , and the other two are indispensable. When it comes to functions, there are two kinds of parameters: called formal parameters and actual arguments. We need to know the difference between the two and know where they are in each place. An argument is an actual argument that is given when the function is called, and the formal parameter is the name we give it when we define the function, and the parameter you can do with how you want to take it, and say here, everyone probably knows how they use it, that is, when you call the function, you copy the arguments to the parameters, so that they correspond, But sometimes the number of formal parameters and arguments is not the same, and then we are in order to give them a corresponding. We can use short-circuit operations to convert them if we encounter a different number. For example:
Function Getsum (a,b,c) {
Console.log (A+b+c)
}
Getsum (10,20)
Function Getsum (a,b,c) {
a=a| | 0
b=b| | 0
c=c| | 0
Console.log (A+b+c)
}
Getsum (10,20)
The two results are different and can be verified by themselves. There is also a return in the function, it is generally used in the function of the three elements of the return value, the general function has a return value, it is returned by return, when the function runs to return, if there is a value after it is returned, if there is no value that will directly jump out of the function. The subsequent code will no longer execute. A single function is almost that much, so the loop statement we learned earlier can be nested, can that function be nested? Answer: Of course, it is possible to use the same thing as a looping statement, which is to nest a function in the first function, for example:
Function Getmax (a,b,c) {
Return Getmax (Getmax (A, B), c)
}
Getmax (10,20,30)
This is the ligatures way, written proficiency can be written so, unskilled can also be written separately
Function Getmax (a,b,c) {
Var d =getmax (A, b);
Var e =getmax (d,e);
Return e;
}
Getmax (10,20,30)
Where Getmax (A, A, b) is a function of two number comparison size. The principle of his work, the first two comparisons to produce results, and the third comparison, used two times Getmax (A, B). The above is what I learned in the new.
JS the third day