This function finds into which the largest equilateral parts the field can be divided.
function field (width, height) {
let big = Math.max(width, height);
let small = Math.min(width, height);
if (big / small === 1){
let arr = [];
arr.push(big);
arr.push(small);
return arr;
}
field(big-small, small);
}
field(1600, 500) // should be [100, 100]
It returns undefined
, but if I use console.log
before, it shows everything OK. Why?