I have an original two-dimensional array representing the full budget for each year, as shown below:
budget = [['2001-01-01', 100], ['2001-01-02', 110], ... , ['2001-12-31', 140]]
Now I want to create subarrays of the budget for specific projects. For example:
project1 = [['2001-01-01', 10], ['2001-01-02', 11]]
This indicates that the project spans 2 days and utilizes 10% of the available budget.
The following function is used to create project arrays:
project1 = [[]];
project1 = new_project(budget, 0, 1, 0.1);
function new_project(origin, start, end, factor) {
var result = [[]];
result = origin.slice(parseInt(start), parseInt(end)).map(function (item) {
return [item[0], parseInt(item[1]) * factor]
});
return result;
}
Issue
How can I update my budget array by subtracting the values of the created projects? I need to adjust the budget dynamically using new_project in order to achieve:
budget = [['2001-01-01', 90], ['2001-01-02', 99],..., ['2001-12-31', 140]]