Note that there are some explanatory texts on larger screens.

plurals
  1. POFind the both next Properties of a given Integer in an Object
    primarykey
    data
    text
    <p>i have an Object</p> <pre> 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 } </pre> <p>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</p> <p>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.</p> <p>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.</p> <p>how can i get these both properties?</p> <p>Thank you</p> <p><strong>EDIT:</strong></p> <p>My solution for that problem is:</p> <pre> 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; } } </pre> <p>as MrP and <a href="https://stackoverflow.com/questions/12505598/get-next-key-value-pair-in-an-object">Get next key-value pair in an object</a> also said that objects are unordered as per ECMAScript's spec, i decided to make an array and iterate throw them.</p> <p>if anyone has a better solution for this would be nice</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload