I am trying to make an array of functions so that I can train a machine learning algorithm. One problem I am running into, for instance:
var fun = [String.prototype.split];
var str = 'test1&test2';
var result = str.fun[0]('&');
gives me the error of "cannot read property 0 of undefined". this is because the str does not have the literal fun array within itself to be called. Is the only way to correct this is to wrap every function such as the following or is there another way:
function splitter (str1, str2) {
return str1.split(str2);
}
var fun = [splitter];
var str = 'test&test';
var result = fun[0](str, '&');
If there is another way to do this I would really like to know as it will save me a lot of time wrapping every function like the above.
var arr = [String.prototype.split];
var str = 'test&test';
arr[0].call(str, '&');
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call