2013-04-10 21:29:02 -07:00
|
|
|
function horner(coeffs, x) {
|
2015-11-18 06:14:39 +00:00
|
|
|
return coeffs.reduceRight( function(acc, coeff) { return(acc * x + coeff) }, 0);
|
2013-04-10 21:29:02 -07:00
|
|
|
}
|
2015-11-18 06:14:39 +00:00
|
|
|
console.log(horner([-19,7,-4,6],3)); // ==> 128
|