Consider an array containing data with increasing percentage values and some missing entries.
For instance:
{
"months": 11,
"factor": 1.31,
"upperMonths": 10.5,
"lowerMonths": 11.49,
"limit": 20,
"percentage": 8
},
{
"months": 10,
"factor": 1.3,
"upperMonths": 9.5,
"lowerMonths": 10.49,
"limit": 20,
"percentage": 9
},
{
"months": 8,
"factor": 1.28,
"upperMonths": 7.5,
"lowerMonths": 8.49,
"limit": 20,
"percentage": 10
},
{
"months": 7,
"factor": 1.27,
"upperMonths": 6.5,
"lowerMonths": 7.49,
"limit": 20,
"percentage": 12
}
Note that percentage 11 is missing...
We have a function that loops through the array and fills in the missing percentages by duplicating the data from the object above, so percentage 11 will now hold the same data as percentage 10.
You can view the function here: http://jsfiddle.net/guideveloper/xnaqtq9y/11/
Our new challenge is to reverse the array and repeat the process. Now, percentage 12 will become the first object, and then the gaps will be filled in reverse order, resulting in an array like this:
{
"months": 7,
"factor": 1.27,
"upperMonths": 6.5,
"lowerMonths": 7.49,
"limit": 20,
"percentage": 12
},
{
"months": 7,
"factor": 1.27,
"upperMonths": 6.5,
"lowerMonths": 7.49,
"limit": 20,
"percentage": 11
},
{
"months": 8,
"factor": 1.28,
"upperMonths": 7.5,
"lowerMonths": 8.49,
"limit": 20,
"percentage": 10
},
{
"months": 10,
"factor": 1.3,
"upperMonths": 9.5,
"lowerMonths": 10.49,
"limit": 20,
"percentage": 9
},
{
"months": 11,
"factor": 1.31,
"upperMonths": 10.5,
"lowerMonths": 11.49,
"limit": 20,
"percentage": 8
}
The array will then need to be reversed back again.
Any thoughts on how to achieve this?