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

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

一个新手
Release: 2017-09-21 10:04:06
Original
2557 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template