Usage of JavaScript

Source: Internet
Author: User
Tags mathematical functions square root


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.