H.C.F Программа расчета
/*
JavaScript H.C.F program by lolman_ks.
Logic is very nicely explained throught comments in the code.
*/
function gcd(){
if(arguments.length == 0) return 1;
if(arguments.length == 1) return arguments[0];
var common_factors = [];
var counter_1 = 1; //For testing different numbers as GCD.
var counter_2 = 0; //For looping through arguments.
//Loop for testing different numbers from 1 to minimum from arguments.
while((counter_1 <= Math.min.apply(null , arguments))){
//Check for exact divisibility of arguments[counter_2] by counter_1.
if(arguments[counter_2] % counter_1 == 0){
++counter_2; //Move to the next item in the array.
}
//If not exactly divisible.
else{
++counter_1; //Test the next number to be tested as GCD.
counter_2 = 0; //Move to the first element of arguments.
}
/*
counter_2 will be == arguments.length, if its value is not
reset and the first condition is true for each element of
the array.
Therefore, the number will be a common factor.
*/
if(counter_2 == arguments.length){
common_factors.push(counter_1); //Add counter_1 to common_factors array.
}
}
return Math.max.apply(null , common_factors);
}
/*
I hope my answers are useful to you, please promote them if they are.
#lolman_ks.
*/
LOLMAN_KS