์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
JavaScript: Greatest Common Divisor (์ต๋ ๊ณต์ฝ์), Least Common Multiple (์ต์ ๊ณต๋ฐฐ์) ๋ณธ๋ฌธ
JavaScript: Greatest Common Divisor (์ต๋ ๊ณต์ฝ์), Least Common Multiple (์ต์ ๊ณต๋ฐฐ์)
yjyuwisely 2023. 6. 29. 15:39
Greatest Common Divisor (์ต๋ ๊ณต์ฝ์)
:the greatest common divisor of two or more integers is the largest positive integer that divides each of the given integers without leaving a remainder.
function GCD(x, y) {
return !x ? y : GCD(y, x % y);
}
!b: to check if the value of b is equal to 0. (! = (logical NOT))
If it is, the function returns a as the greatest common divisor.
If b is not equal to 0, the function calls itself recursively, passing b as the new value of a and the remainder of a divided by b (a % b) as the new value of b.
This process continues until b becomes 0, at which point the function returns a as the greatest common divisor.
Least Common Multiple (์ต์ ๊ณต๋ฐฐ์)
The GCD represents the largest positive integer that divides both x and y without leaving a remainder.
function LCM(x, y) {
return (x * y) / GCD(x, y);
}
1. The GCD(x, y) function is called to calculate the GCD of x and y.
2. The product of x and y is divided by the GCD using the division operator /.
3. The result is the LCM of x and y.
'๐ปBootcamp Self-Study Revisionโจ > JavaScript, jQuery, Ajax' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Differences between Spring/JSP and React/TypeScript for CRUD Operations (0) | 2023.07.31 |
---|---|
The pros and cons of using Axios and Fetch API (0) | 2023.07.31 |
JavaScript: padStart, padEnd, map() (0) | 2023.06.28 |
JavaScript: ๋ฐ์ฝ๋ Generator์์ QR์ฝ๋๋ก ๋ฌผํ ์ด๋ฆ ์ฝ๊ธฐ (0) | 2023.06.27 |