> & : Bitwise AND, determine parity; do bitwise AND between any number and 1, the result is 1, then it is an odd number; if the result is 0, it is an even number | : Bitwise OR, round the decimal; do the bitwise bit between any decimal and 0 Bit or, if saved, take the integer part ^: Press"/> > & : Bitwise AND, determine parity; do bitwise AND between any number and 1, the result is 1, then it is an odd number; if the result is 0, it is an even number | : Bitwise OR, round the decimal; do the bitwise bit between any decimal and 0 Bit or, if saved, take the integer part ^: Press">

Home  >  Article  >  Web Front-end  >  How to define a function that can receive three numbers and output

How to define a function that can receive three numbers and output

一个新手
一个新手Original
2017-09-21 10:04:062474browse

Define a function that can receive three numbers, and implement the sorted output of three numbers in the function body → (declaration and call of the function that returns the value in javascript)

Analysis of "bit operator" Knowledge:

4. Bit operators
Tags: >> << & | ^
&: Bitwise AND, determine parity; do bitwise AND between any number and 1, if the result is 1, it is an odd number; if the result is 0, it is an even number
|: Bitwise OR, for Decimal rounding; any decimal is bitwise ORed with 0, and if it is saved, the integer part is taken
^: Bitwise XOR, used to exchange two numbers
a = a^b; b = b^a; a = a^b;
Abbreviation: a^=b; b^=a; a^=b;

<!doctype html>
<html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>Document</title>
	 <link rel="stylesheet" style="text/css" href="">
     <style></style>
	 <script></script>
 </head>
 <body>
 <!
定义一个可以接收三个数字的函数,函数体内实现三个数字的排序输出 
-->
	<script>
		function sortNum(a,b,c){
	//如果将最小的数字赋值给a,将最大的数字赋值给c
	//1.比较a与b的大小关系,如果a>b的话,则交换两个数字,则a中存放的就是 a和b 的最小值。
			a>b && (a^=b,b^=a,a^=b);
	//2.比较b与c的大小关系,如果b>c的话,则交换两个数字,则b中存放的就是 b和c 的最小值;则c中存放的是3个数字中的最大值。
			b>c && (b^=c,c^=b,b^=c);
	//3.最后在比较a与b中的(两个最小值的大小)大小关系,如果a>b的话,则交换两个数字,则a中存放的就是 a和b 的最小值。
			a>b && (a^=b,b^=a,a^=b);
			console.log(a,b,c);
		}
	</script>
	<button onclick="sortNum(52,36,98)">三个数字的排序</button>
 </body>
</html>

The above is the detailed content of How to define a function that can receive three numbers and output. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn