The reflectAboutYAxis function works only for polynomials of even degree.
Indeed, because the polynomial is given as an array from highest to lowest power, if the polynomial has an even degree, the odd coefficients are negated, but if the polynomial has an odd degree, then the even coefficients are negated which is not correct.
One fix is to replace line 23 with if (i % 2 === (d - 1) % 2).
The
reflectAboutYAxis
function works only for polynomials of even degree.Indeed, because the polynomial is given as an array from highest to lowest power, if the polynomial has an even degree, the odd coefficients are negated, but if the polynomial has an odd degree, then the even coefficients are negated which is not correct.
One fix is to replace line 23 with
if (i % 2 === (d - 1) % 2)
.