From dd5c896cb442ce7d567e1fd7c470816ef6094a92 Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Tue, 4 Oct 2022 11:04:32 +0200 Subject: [PATCH] Horner method class --- horner.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 horner.ts diff --git a/horner.ts b/horner.ts new file mode 100644 index 0000000..9e52673 --- /dev/null +++ b/horner.ts @@ -0,0 +1,50 @@ +class Horner { + + constants: number[]; + + constructor(constants: number[]) { + this.constants = constants; + } + + candidates() { + // Not effective solution + let max = Math.abs(this.constants[0]) + Math.abs(this.constants[this.constants.length - 1]); + let min = 1; + let candidates: number[] = []; + for(let i = min; i<=max; i++) { + candidates.push(i); + candidates.push(-i); + } + return candidates; + } + + functional_value(number: number) { + let new_polynom = [this.constants[0]]; + for(let i=1; i