Mistakes in sorting of results
-
Hi.
I have a calculator where users enter loan amount and time and see how much they will pay in 25 credit companies.
In order to sort results from lowest to highest I`ve inserted hidden calculated field with the following code:
(function myfun() {
var list = {};list[fieldname17] = jQuery(‘.cont02’);
list[fieldname27] = jQuery(‘.cont03’);
list[fieldname35] = jQuery(‘.cont04’);
list[fieldname41] = jQuery(‘.cont05’);
list[fieldname49] = jQuery(‘.cont06’);
list[fieldname58] = jQuery(‘.cont07’);
list[fieldname72] = jQuery(‘.cont08’);
list[fieldname81] = jQuery(‘.cont09’);
list[fieldname90] = jQuery(‘.cont10’);
list[fieldname99] = jQuery(‘.cont11’);
list[fieldname108] = jQuery(‘.cont12’);
list[fieldname114] = jQuery(‘.cont13’);
list[fieldname120] = jQuery(‘.cont14’);
list[fieldname129] = jQuery(‘.cont15’);
list[fieldname138] = jQuery(‘.cont16’);
list[fieldname147] = jQuery(‘.cont17’);
list[fieldname155] = jQuery(‘.cont18’);
list[fieldname165] = jQuery(‘.cont19’);
list[fieldname170] = jQuery(‘.cont20’);
list[fieldname179] = jQuery(‘.cont21’);
list[fieldname188] = jQuery(‘.cont22’);
list[fieldname194] = jQuery(‘.cont23’);
list[fieldname203] = jQuery(‘.cont24’);
list[fieldname212] = jQuery(‘.cont25’);
var keys = Object.keys(list);
keys.sort(function (a, b) { return b – a });var tmp;
for (var i = 0; i < keys.length; i++) {
if(typeof tmp == ‘undefined’)
{
tmp = i; continue;
}
list[keys[tmp]].before( list[keys[i]]);
delete list[keys[tmp]];
tmp = i;
}
return keys;
})()“return keys” has been inserted only to identify the problem.
And the first credit company is not inserted deliberately in order to be showed first.The problem is that this code works fine only until I show no more than 13 companies.
If the user is able to obtain loan from 14 companies or more – the last 13 are showed correctly, the first ones – randomly.
“return keys” shows that variable keys stores no more than 14 values (one of them “0”).
What puzzles me is that I have a similar calculator and there similar code works completely fine.
Could you please point me into direction why it doesn`t work with more than 13 companies here?
the page is https://finsee.com/test/
- The topic ‘Mistakes in sorting of results’ is closed to new replies.