Created
May 3, 2014 01:12
-
-
Save smokinjoe/ccf599bf3b0a87055d24 to your computer and use it in GitHub Desktop.
function to find the next/prev value in an array (circular)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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