Skip to content

@chrsr /script.js
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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 min, max, available, i, index = 0, found, numbers = [];
// http://ejohn.org/blog/fast-javascript-maxmin
Array.max = function( array ){
return Math.max.apply( Math, array );
};
Array.min = function( array ){
return Math.min.apply( Math, array );
};
// Sorting function
function compareNumbers(a, b) {
return a - b;
}
// get only the numbers
$.each(myobjs, function(key, it) {
if (it.position) {
numbers.push(it.position);
}
});
numbers.sort(compareNumbers);
min = Array.min(numbers); // if min is not 1 then return 1 perhaps?
max = Array.max(numbers);
for (i = min; i < max; i++) {
if (i !== numbers[index]) {
available = index + 1;
break;
}
index++;
}
console.log(available);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.