mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
Merge pull request #57 from christianbender/changed_euclian
added the let-statment
This commit is contained in:
@ -5,7 +5,7 @@ function euclideanGCDRecursive (first, second) {
|
|||||||
:param second: Second number
|
:param second: Second number
|
||||||
:return: GCD of the numbers
|
:return: GCD of the numbers
|
||||||
*/
|
*/
|
||||||
if (second === 0) {
|
if (second == 0) {
|
||||||
return first;
|
return first;
|
||||||
} else {
|
} else {
|
||||||
return euclideanGCDRecursive(second, (first % second));
|
return euclideanGCDRecursive(second, (first % second));
|
||||||
@ -19,8 +19,8 @@ function euclideanGCDIterative (first, second) {
|
|||||||
:param second: Second number
|
:param second: Second number
|
||||||
:return: GCD of the numbers
|
:return: GCD of the numbers
|
||||||
*/
|
*/
|
||||||
while (second !== 0) {
|
while (second != 0) {
|
||||||
var temp = second;
|
let temp = second;
|
||||||
second = first % second;
|
second = first % second;
|
||||||
first = temp;
|
first = temp;
|
||||||
}
|
}
|
||||||
@ -28,8 +28,8 @@ function euclideanGCDIterative (first, second) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main () {
|
function main () {
|
||||||
var first = 20;
|
let first = 20;
|
||||||
var second = 30;
|
let second = 30;
|
||||||
console.log('Recursive GCD for %d and %d is %d', first, second, euclideanGCDRecursive(first, second));
|
console.log('Recursive GCD for %d and %d is %d', first, second, euclideanGCDRecursive(first, second));
|
||||||
console.log('Iterative GCD for %d and %d is %d', first, second, euclideanGCDIterative(first, second));
|
console.log('Iterative GCD for %d and %d is %d', first, second, euclideanGCDIterative(first, second));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user