From 563ca0a35e98678e2b7d5f154f31f496851e8d60 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:07 +0800 Subject: remove code tag inside pre tag for zh-CN --- .../web/javascript/reference/global_objects/math/pi/index.html | 4 ++-- .../javascript/reference/global_objects/math/random/index.html | 10 +++++----- .../javascript/reference/global_objects/math/sign/index.html | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/math') diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html index fcfc82fbd5..efc463d5b7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html @@ -23,11 +23,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/PI

下面的函数使用 Math.PI 计算给定半径的圆周长:

-
function calculateCircumference (radius) {
+
function calculateCircumference (radius) {
   return 2 * Math.PI * radius;
 }
 
-calculateCircumference(1);  // 6.283185307179586
+calculateCircumference(1); // 6.283185307179586

规范

diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html index 91796ae506..04602b2699 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html @@ -50,11 +50,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

这个例子返回了一个在指定值之间的随机整数。这个值不小于 min (如果 min 不是整数,则不小于 min 的向上取整数),且小于(不等于)max

-
function getRandomInt(min, max) {
+
function getRandomInt(min, max) {
   min = Math.ceil(min);
   max = Math.floor(max);
-  return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值
-}
+ return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值 +}

也许很容易想到用 Math.round() 来实现,但是这会导致你的随机数处于一个不均匀的分布,这可能不符合你的需求。

@@ -64,11 +64,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

上一个例子提到的函数 getRandomInt() 结果范围包含了最小值,但不含最大值。如果你的随机结果需要同时包含最小值和最大值,怎么办呢?  getRandomIntInclusive() 函数可以实现。

-
function getRandomIntInclusive(min, max) {
+
function getRandomIntInclusive(min, max) {
   min = Math.ceil(min);
   max = Math.floor(max);
   return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 
-}
+}

规范

diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html index 60808dde44..590089e3c1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html @@ -50,12 +50,12 @@ Math.sign(); // NaN

Polyfill

-
function sign(x) {
+
function sign(x) {
     x = +x ;// convert to a number
     if (x === 0 || isNaN(x))
         return x;
     return x > 0 ? 1 : -1;
-}
+}

 

-- cgit v1.2.3-54-g00ecf