first, bubble sort
var arr = new Array (70,34,60,49,20,59,9,78,38,97);
var ZJ = 0;//Intermediate variable
//For the first time for the number of wheels to control the comparison, I represents the round
For (Var i=1;i<arr.length;i++) {
//control how many times each round is compared
For (Var j=0;j<arr.length-i;j++) {
if (arr[j]<arr[j+1]) {
//Implement Exchange
ZJ = arr[j];
arr[j]=arr[j+1];
Arr[j+1]=zj;
}
}
}
alert (arr[0]);
Two or two-point method to find data
var arr = new Array (1,2,3,4,5,6,7,8,9,10);
var a = 2;
var minx = 0;
var maxx = arr.length-1;
while (true)
{
var zjx = parseint ((minx+maxx)/2);
if (Zjx==minx)
{ Br> if (a==arr[zjx+ 1])
{ Br> alert (zjx+1);
break;
} Br> }
if ( A==ARR[ZJX])
{
alert (ZJX);
Break
}else if (A>ARR[ZJX])
{
Minx = ZJX;
}
Else
{
Maxx = ZJX;
}
}
Three, date time function (need to call with a variable):
var b = new Date ();//Get Current time
b.gettime ()//Get timestamp
b.getfullyear ()//Get year
b.getmonth () +1;//Get month
b.getdate ()//Get Day
b.gethours ()//Get hours
b.getminutes ()//Get minutes
b.getseconds ()//Get the number of seconds
b.getday ()//Get the day of the week
b.getmilliseconds ()//Get milliseconds
Iv. Mathematical functions (called with math):
ABS (x) The absolute value of the return number.
ceil (x) is rounded on the logarithm.
Floor (x) is rounded down with a logarithmic.
round (x) rounds the number to the nearest integer.
Max (x, y) returns the highest value in X and Y.
min (x, y) returns the lowest value in X and Y.
the POW (x, y) returns the y power of X.
sqrt (x) returns the square root of the number.
random () returns an arbitrary number between 0 and 1.
Usage of JavaScript