Skip to content

Instantly share code, notes, and snippets.

@smokinjoe
Created May 3, 2014 01:12
Show Gist options
  • Save smokinjoe/ccf599bf3b0a87055d24 to your computer and use it in GitHub Desktop.
Save smokinjoe/ccf599bf3b0a87055d24 to your computer and use it in GitHub Desktop.
function to find the next/prev value in an array (circular)
return function (_array, _id) {
var _result = {};
var _clean_array = _.compact(_array);
_result.next = _clean_array[($.inArray(_id, _clean_array) + 1) % _clean_array.length];
_result.prev = _clean_array[($.inArray(_id, _clean_array) - 1 + _clean_array.length) % _clean_array.length];
return _result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment