Math.floor():取得最大整數
const mathFloor=Math.floor(1.6); console.log(mathFloor); //1
Math.imul(3, 4);//12 Math.imul(-5, 12);//-60
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(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
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(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
//方法會傳回一個新字串,此新字串是透過將原字串與 pattern 比對,以 replacement 取代吻合處而生成
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
const p
const pReplace=p.replace('dog', 'monkey');
console.log('Preplace',pReplace);
//"The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
const pReplaceAll=p.replaceAll('dog', 'monkey');
console.log('PreplaceAll',pReplaceAll);
//"The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
//"The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
參數(第一個參數,數量,數據)
第一個參數可以是字串,數字,
第二個參數一定是數量:0~…
第三個參數可以是字串,數字:如果有為取代,如果沒有為新增
const arr =["apple","book","phone"]
const arrSplice=arr.splice("apple",1);
console.log('arrSplice',arrSplice);
//arrSplice ["apple"]
console.log('arr',arr);
//arr ["book","phone"]
const arry =["apple","book","phone"];
const arrySplice=arry.splice("apple",1,"spack");
console.log('arrySplice',arrySplice);
//"arrySplice" ["apple"]
console.log('arry',arry);
//"arry" ["spack","book","phone"]
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,0,"Lemon","Kiwi");
console.log('fruits',fruits);
//"fruits" ["Banana","Orange","Lemon","Kiwi","Apple","Mango"]