The constructor function of the Interpolation
class takes in two arrays. How can I set a restriction so that during object creation the length of these two arrays must be equal.
class Interpolation {
constructor (x, fx) {
if ( x instanceof Array && fx instanceof Array ) {
if ( x.length === fx.length ) {
this.input = x;
this.output = fx;
} else { throw 'Unmatching array' }
} else throw 'Please pass in array';
}
}
I tried this and during object creating the source code was also printed on the console like this
C:\NeuralNetwork\interpolation.js:7
} else { throw('Invalid Array') }
^
Invalid Array