var AddAt = function (array, item, index, limit, callback, context){ if (index === undefined) { index = 0; } if (context === undefined) { context = array; } if (limit) { var remaining = limit - _AN_Read_length('length', array); if (remaining <= 0) { return null ; } } if (!Array.isArray(item)) { if (array.indexOf(item) === -1) { array.splice(index, 0, item); if (callback) { callback.call(context, entry); } return item; } else { return null ; } } var itemLength = _AN_Read_length('length', item) - 1; while (itemLength >= 0){ if (array.indexOf(item[itemLength]) !== -1) { item.pop(); } itemLength-- ; } itemLength = _AN_Read_length('length', item); if (itemLength === 0) { return null ; } if (limit && itemLength > remaining) { item.splice(remaining); itemLength = remaining; } for (var i = itemLength; i > 0; i-- ){ var entry = item[i]; array.splice(index, 0, entry); if (callback) { callback.call(context, entry); } } return item; } ; module.exports = AddAt;