编辑代码

//递归
const dividetoSquare = (lenght, width) => {
    if(lenght % width == 0){
        return width;
    }

    return dividetoSquare(width, lenght%width);
}

//递推
const dividetoSquareIter = (lenght, width) => {
    let w = lenght % width;

    while(w > 0){
        lenght = width;
        width = w;
        w = lenght % width;
    }

    return width;
}

console.log(dividetoSquare(1680,640))
console.log(dividetoSquareIter(1680,640))