i have an Object
marks: { 900: 1.0, 822: 1.1, 804: 1.2, 786: 1.3, 768: 1.4, 750: 1.5, 732: 1.6, 714: 1.7, 696: 1.8, 678: 1.9, 660: 2.0, 588: 2.4, 570: 2.5, 552: 2.6, 534: 2.7, 516: 2.8, 498: 2.9, 480: 3.0, 462: 3.1, 444: 3.2, 426: 3.3, 408: 3.4, 390: 3.5, 372: 3.6, 354: 3.7, 336: 3.8, 318: 3.9, 300: 4.0 }
This object is a mark-list. if you get 900 points you get the mark 1.0. you get the mark 1 until you get 823 points. on 822 points => mark 1.1
now i have 690 points. i want the know the both next object properties with the given points. in this example: the lower: 678: 1.9 and the upper 696: 1.8.
except i get a full hit on the propertie i.e. 570 points i want have three properties returned: the lower, the upper and the full hit.
how can i get these both properties?
Thank you
EDIT:
My solution for that problem is:
var a = new Array(), r = new Array(), points = 300; for(var key in this.options.marks){ a.push({'points':key, 'mark': this.options.marks[key]}); } a.reverse(); for (var i=0; i a[i].points) { r.push({'points':a[(i-1)].points, 'mark': a[(i-1)].mark}); r.push({'points':points, 'mark': a[(i-1)].mark}); r.push({'points':a[i].points, 'mark': a[i].mark}); break; }else if(points == a[i].points) { if(typeof a[i-1] != 'undefined'){ r.push({'points':a[i-1].points, 'mark': a[i-1].mark}); }else{ r.push({'points':a[i].points, 'mark': a[i].mark}); } r.push({'points':a[i].points, 'mark': a[i].mark}); if(typeof a[i+1] != 'undefined'){ r.push({'points':a[i+1].points, 'mark': a[i+1].mark}); }else{ r.push({'points':a[i].points, 'mark': a[i].mark}); } break; } }
as MrP and Get next key-value pair in an object also said that objects are unordered as per ECMAScript's spec, i decided to make an array and iterate throw them.
if anyone has a better solution for this would be nice