63
rated 0 times
[
70]
[
7]
/ answers: 1 / hits: 44021
/ 10 Years ago, thu, november 6, 2014, 12:00:00
I'm trying to implement a vector object instantiated like below...
var a = new Vector([1,2,3]);
var b = new Vector ([2,2,2]);
...and when I do a math operation I need something like this...
a.add(b); // should return Vector([3,4,5])
...but my code below returns me just an array
function Vector(components) {
// TODO: Finish the Vector class.
this.arr = components;
this.add = add;
}
function add(aa) {
if(this.arr.length === aa.arr.length) {
var result=[];
for(var i=0; i<this.arr.length; i++) {
result.push(this.arr[i]+aa.arr[i]);
}
return result;
} else {
return error;
}
}
Please help me out here. Thank you!
More From » arrays