Hello i within javascript a function to calculate the stock of our ticket system. As input i get the following input:
[{key:"10-09-2017", value:{countCreatedTickets: 98, countOpenTickets: 13, countSolvedTickets: 61}},
{key:"12-09-2017", value:{countCreatedTickets:51, countOpenTickets: 14, countSolvedTickets: 33}}
]
The function as i used is:
function funnelCalulation(ds){
var stock = 0, stockCalulations = []
console.info('------- funnelCalulation -------')
console.info(ds)
ds = ds.reverse()
for(var i = 0; i < ds.length; i++ ){
if (i == 0){
stock = ( ds[i].value.countCreatedTickets + ds[i].value.countOpenTickets ) - ds[i].value.countSolvedTickets
stockCalulations.push({datum: ds[i].key, createdTickets: ds[i].value.countCreatedTickets, opentTickets: ds[i].value.countOpenTickets, ticketStock: stock })
}
if (i > 0){
stock = ( ds[i].value.countCreatedTickets + ds[i].value.countOpenTickets + stock ) - ds[i].value.countSolvedTickets
stockCalulations.push({datum:ds[i].key, createdTickets: ds[i].value.countCreatedTickets, opentTickets: ds[i].value.countOpenTickets, ticketStock: stock })
}
}
return stockCalulations[ds.length-1]
}
I called the function as followed:
var stockValues = funnelCalulation(values)
console.info(' ---- > stockValues <--------')
console.info(stockValues)
console.info(ds) returns the following output:

and if i type typeof ds it returns that is a object. The result is the function works correct but when returning the value gives the following error back:
ticketsGraphs.js:49 Uncaught TypeError: ds.reverse is not a function
at funnelCalulation (ticketsGraphs.js:49)
at Object.success (createWidgets.js:121)
at i (jquery-3.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
at A (jquery-3.2.1.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-3.2.1.min.js:4)
I put the complete code in the jsfilde below: