I’m not looking for solutions to this code, rather looking why the current code is failing.
function HFC_x(x) {
let xArr = [];
let i = x;
while (i > 1 && x % i == 0) {
xArr.push(i);
i--;
}
console.log(xArr);
}
HFC_x(15);
The code is for HCF. I am planning to do it this way.
This is how I want to to do GCD
I don’t want to directly use Euclid’s algorithm, I want to use it different way.
I first divide 15 by 3, then….till I get 1 as divisor.
Same for 12.
Currently, my code is only publishing 15. As I said I’m not looking for code solutions, but rather why is this happening. I tried debugger in vs code but it was not showing full steps/logs.