@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
21 lines (20 loc) • 728 B
JavaScript
import findIndex from 'lodash/findIndex';
import isString from 'lodash/isString';
export function getNextItemIdFromArray(itemId, items) {
if (items.length > 1) {
// the array can have objects or strings
var indexCurrentItem = findIndex(items, function(item) {
return item.id === itemId || item === itemId;
});
// get previous item if exists, else the next item
var nextItem = items[indexCurrentItem - 1] || items[indexCurrentItem + 1];
if (nextItem.id) {
// if nextItem is an object with an id
return nextItem.id;
}
if (isString(nextItem)) {
// if nextItem a sting
return nextItem;
}
}
}