Skip to content

Smert/math-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

math-algoritms

Experiment. Bad code. Do not use it.

function toFunction(arr) {
  var f = [];
  for (var i = 0; i < arr.length; i++) {
    var a = arr[i];
    var b = [];
    for (var j = 0; j < arr.length; j++) {
      if (j === i) continue;
      a /= j - i;
      b.push('(' + j + '-x)');
    }
    f.push('(' + a + '*' + b.join('*') + ')');
  }
  return Function('x', 'return ' + f.join('+') + ';');
}
var a = toFunction([5,7,4,3]);

a(0) === 5
a(1) === 7
a(2) === 4
a(3) === 3
var a = toFunction([1,2,3]);

a(0) === 1
a(1) === 2
a(2) === 3
a(3) === 4
a(4) === 5
a(10) === 11

About

Experiment. Bad code. Do not use it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published