public
Created

A CodePen by Chris Roberts.

  • Download Gist
script.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
var myobjs = [
{position: null},
{position: null},
{position: 5},
{position: 1},
{position: null},
{position: 6},
{position: 3},
{position: 10},
{position: 2},
{position: 11},
{position: null},
{position: 4},
{position: null},
{position: 15},
{position: null},
{position: 0}
];
 
var nextAvailable,
j, i, it, found;
 
for (i = 0; i < myobjs.length; i++) {
for (j = 0; j < myobjs.length; j++) {
it = myobjs[j];
if (it.position && it.position === i) {
found = i;
}
}
if (found === i - 1) {
nextAvailable = i;
break;
}
}
 
console.log(nextAvailable);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.