Math.abs():返回數字的絕對值

Math.abs():將其參數強制為數字。不可強制值將變為NaN,Math.abs()也使得返回NaN

Math.abs("-1"); // 1
Math.abs(-2); // 2
Math.abs(null); // 0
Math.abs(""); // 0
Math.abs([]); // 0
Math.abs([2]); // 2
Math.abs([1, 2]); // NaN
Math.abs({}); // NaN
Math.abs("string"); // NaN
Math.abs(); // NaN

Math.atan()

Math.atan():// 以弧度計算直角三角形的角度

function calcAngle(opposite, adjacent) {
  return Math.atan(opposite / adjacent);
}


console.log(calcAngle(8, 10));
// Expected output: 0.6747409422235527

console.log(calcAngle(5, 3));
// Expected output: 1.0303768265243125

Math.min():查詢最小值

Math.min():查詢最小值

var myArray1 = [1, 5, 6, 2, 3];
var min1 = Math.min(...myArray1);

//console.log(min1),
//1

var myArray2 = [1, 5, 6, 2, 3];
var min2 = Math.min.apply(null, myArray2);
console.log(min2)
//1


function MyMin(myarr){
    var al = myarr.length;
    minimum = myarr[al-1];
    while (al--){
        if(myarr[al] < minimum){
            minimum = myarr[al]
        }
    }
    return minimum;
};
var myArray3 = [1, 5, 6, 2, 3];
var min3 = MyMin(myArray3);
console.log(min3)

Math.pow():次方根

Math.pow():將其參數強制為數字。不可強制值將變為NaN,Math.abs()也使得返回NaN

Math.pow(x,y)=Xy
x:基數
y:指數

console.log(Math.pow(7, 3));
// Expected output: 343

console.log(Math.pow(4, 0.5));
// Expected output: 2

console.log(Math.pow(7, -2));
// Expected output: 0.02040816326530612
//                  (1/49)

console.log(Math.pow(-7, 0.5));
// Expected output: NaN

Math.sin()

Math.sin():

function getCircleY(radians, radius) {
  return Math.sin(radians) * radius;
}

console.log(getCircleY(1, 10));
// Expected output: 8.414709848078965

console.log(getCircleY(2, 10));
// Expected output: 9.092974268256818

console.log(getCircleY(Math.PI, 10));
// Expected output: 1.2246467991473533e-15

Math.sqrt():平方根

Math.sqrt():

Math.sqrt(x)=√ ̄=the unique y>=0 such that y2=x

function calcHypotenuse(a, b) {
  return (Math.sqrt((a * a) + (b * b)));
}

console.log(calcHypotenuse(3, 4));
// Expected output: 5

console.log(calcHypotenuse(5, 12));
// Expected output: 13

console.log(calcHypotenuse(0, 0));
// Expected output: 0