How can I extract negative numbers and positive numbers separately from JSON data obtained from the server using the $http.get method? One of the fields in the data is called Credits, which contains both negative and positive values. Can anyone help me with this?
Array.prototype.sum = function (prop) {
var total = 0
for (var i = 0, _len = this.length; i < _len; i++) {
total += parseInt(this[i][prop])
}
return total
}
$scope.totalCreadit = function (arr) {
return arr.sum("credits");
}
This function provides the totals, but I need to separate the total for negative values and positive values.
Thank you in advance.