search():在字符串中搜索一個值並返回第一個匹配項的位置
將字符串與正則表達式匹配**
返回第一個匹配項的索引(位置)
如果未找到匹配項,則該方法返回 -1
方法區分大小寫
const arr="Mr. Blue has a blue house";
const searchArr=arr.search("Blue")
console.log(searchArr)
//4
const anyString = "Brave new world"; console.log(anyString.charAt(0))//"B" console.log(anyString.charAt(1))//"r" console.log(anyString.charAt(3))//"v" console.log(anyString.charAt(4))//"e" console.log(anyString.charAt(5))//"n" console.log(anyString.charAt(6))//" " console.log(anyString.charAt(999))//" "
function calcAngleDegrees(x, y) {
return Math.atan2(y, x) * 180 / Math.PI;
}
console.log(calcAngleDegrees(5, 5));
// Expected output: 45
console.log(calcAngleDegrees(10, 10));
// Expected output: 45
console.log(calcAngleDegrees(0, 10));
// Expected output: 90
var myArray1 = [1, 5, 6, 2, 3];
var max1 = Math.max(...myArray1);
console.log('max1',max1)
//"max1" 6
function MyMax(myarr){
var al = myarr.length;
maximum = myarr[al-1];
while (al--){
if(myarr[al] > maximum){
maximum = myarr[al]
}
}
return maximum;
};
var myArray2 = [1, 5, 8, 2, 3];
var max2 = MyMax(myArray2);
console.log('max2',max2)
//"max2" 8
function getTanFromDegrees(degrees) {
return Math.tan(degrees * Math.PI / 180);
}
console.log(getTanFromDegrees(0));
// Expected output: 0
console.log(getTanFromDegrees(45));
// Expected output: 0.9999999999999999
console.log(getTanFromDegrees(90));
// Expected output: 16331239353195370
function getCircleX(radians, radius) {
return Math.cos(radians) * radius;
}
console.log(getCircleX(1, 10));
// Expected output: 5.403023058681398
console.log(getCircleX(2, 10));
// Expected output: -4.161468365471424
console.log(getCircleX(Math.PI, 10));
// Expected output: -10