Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- for..of
- 고차함수
- indexOf
- 배열의 내림차순
- map()
- filter()
- classList.contains(string)
- Link
- 인접 형제 선택자 결합
- 쌍방향 연결리스트
- Em
- 일반 형제 선택자 결합
- Sort
- disabled
- CSS
- 범용 선택자
- Array.from()
- nth-child()
- display : none
- 양방향 연결리스트
- 백준알고리즘
- 단방향 연결리스트
- 배열의 오름차순
- innerhtml
- invalid assignment left-hand side
- 객체
- 배열과 연결리스트의 차이
- visibility : hidden
- 등차수열의 항 찾기
- 가상 요소 선택자
Archives
- Today
- Total
프론트엔드 센트럴파크 (☞゚ヮ゚)☞
Math() 본문
표준 Built-in 객체로써 수학적인 연산을 위한 속성값과 메서드를 제공하는 객체
Math는 생성자 함수가 아니며, 모든 속성과 메서드는 정적이기에 Math.function()으로 언제든 호출 가능
Math.max()
: 최대값
console.log(Math.max(1, -1)); // output : 1
Math.min()
: 최소값
console.log(Math.min(1, -1)); // output : -1
배열로 값을 넘겨주게 될 때 처리하는 방법
let nums = [1, 5, 65, 88, 45, 66, 75, 6];
console.log(Math.max(nums));
console.log(Math.max.apply(null, nums));
console.log(Math.min.apply(null, nums));
max로 받는 인자값들이 다 values 값만 받기 때문이다.
그래서 배열에 대한 처리를 해주어야 한다. => apply() 사용
스프레드 문법을 이용한 max/min값 호출하기
let nums = [1, 5, 65, 88, 45, 66, 75, 6];
console.log(Math.max(nums));
console.log(Math.max(...nums));
console.log(Math.min(...nums));
Math.abs()
: 절대값
let nums = [1, 5, 65, 88, 45, 66, 75, 6];
console.log(Math.max(nums));
console.log(Math.abs(1));
console.log(Math.abs(-1));
Math.random()
: 0과 1 사이의 랜덤값
console.log(Math.random());
// 1의자리 랜덤구하기
console.log(Math.random() *10);
console.log(Number.parseInt(Math.random() *10));
console.log(Number.parseInt(Math.random() *100));
반복문을 통한 랜덤값
for(let i=0; i< 10; i++) {
console.log(Number.parseInt(Math.random() * 10));
}
Mah.pow(x,y)
: 제곱
console.log(Math.pow(2,3)); // output : 8
console.log(2 ** 3); // output : 8
Math.sqrt(x)
: 제곱근(루트)
console.log(Math.sqrt(4)); // output : 2
console.log(Math.sqrt(2)); // output : 1.4142135623730951
'Javascript' 카테고리의 다른 글
2차원 배열 반복문 (0) | 2022.06.04 |
---|---|
Date() (0) | 2022.06.04 |
String.prototype.toString() - 객체의 문자열 표현 (0) | 2022.06.03 |
함수표현식 - 기명함수 표현식, 익명함수 표현식 (0) | 2022.06.03 |
set() - 반복문 (0) | 2022.05.31 |
Comments