Having trouble creating an array of objects from one class in another class. When I try to push them, an error occurs saying "Cannot read property '0' of undefined." Any help would be greatly appreciated. Here is an example using typescript:
export class Vector {
private elements:Array<number>
constructor(n:number, k:number){
this.elements = []
for (let i=0; i<n; i++) {
this.elements.push(Math.floor(Math.random()*k)+1);
}
}
}
class Matrix {
private elements:Vector[];
constructor(n:number, m:number, k:number) {
this.elements = new Array();
for (let i=0; i<n; i++){
for (let j=0; j<m; j++) {
this.elements[i][j].push(Math.floor(Math.random()*k)+1)
}
}
}
}