ECMA Script don't have operator overloading.
First way, use QScript like Cpp:
arrayA = [0.1, 0.4, 0.5]
arrayB = [0.1, 0.1, 0.7]
arrayC = [0.6, 0.23, 0.44]
for ( var idx = 0; idx < aArray.length; ++idx) {
result[idx] = aArray[idx]^2 + bArray[idx]/cArray[idx].
}
arrayA = [0.1, 0.4, 0.5]
arrayB = [0.1, 0.1, 0.7]
arrayC = [0.6, 0.23, 0.44]
for ( var idx = 0; idx < aArray.length; ++idx) {
result[idx] = aArray[idx]^2 + bArray[idx]/cArray[idx].
}
To copy to clipboard, switch view to plain text mode
Second way create functions for array prototype:
Array.prototype.addition = function(other) {
var result;
for (var i; i < this.length; ++i) {
result[i] = this[i] + other[i];
}
return result;
}
Array.prototype.division = function(other) {
var result;
for (var i; i < this.length; ++i) {
result[i] = this[i]/other[i];
}
return result;
}
Array.prototype.power = function(number) {
var result;
for (var i; i < this.length; ++i) {
result[i] = Math.pow(this[i], other[i]);
}
return result;
}
Array.prototype.addition = function(other) {
var result;
for (var i; i < this.length; ++i) {
result[i] = this[i] + other[i];
}
return result;
}
Array.prototype.division = function(other) {
var result;
for (var i; i < this.length; ++i) {
result[i] = this[i]/other[i];
}
return result;
}
Array.prototype.power = function(number) {
var result;
for (var i; i < this.length; ++i) {
result[i] = Math.pow(this[i], other[i]);
}
return result;
}
To copy to clipboard, switch view to plain text mode
Using
arrayA = [0.1, 0.4, 0.5]
arrayB = [0.1, 0.1, 0.7]
arrayC = [0.6, 0.23, 0.44]
result = (arrayA.power(2)).addition(bArray.division(cArray));
//result[idx] = aArray[idx]^2 + bArray[idx]/cArray[idx]
arrayA = [0.1, 0.4, 0.5]
arrayB = [0.1, 0.1, 0.7]
arrayC = [0.6, 0.23, 0.44]
result = (arrayA.power(2)).addition(bArray.division(cArray));
//result[idx] = aArray[idx]^2 + bArray[idx]/cArray[idx]
To copy to clipboard, switch view to plain text mode
Bookmarks