I found this function to put numbers in fractions and I am trying to figure out what everything means. There is one thing I can't figure out.
Here's the code:
function reduce(numerator,denominator) {
var gcd = function gcd (a,b) {
if (b) {
return gcd(b, a%b);
} else {
return a;
}
};
gcd = gcd(numerator,denominator);
return [numerator/gcd, denominator/gcd];
}
What does the if (b)
mean. I know that if there is just the variable in the if statement it is checking if the variable is true or false. How would this apply to a number? When would this go to the else statement?
This is to do with how things get converted to Boolean, i.e. whether something is truthy or not