Skip to content

Instantly share code, notes, and snippets.

@chrsr
Created March 13, 2013 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrsr/5156791 to your computer and use it in GitHub Desktop.
Save chrsr/5156791 to your computer and use it in GitHub Desktop.
A CodePen by Chris Roberts.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment