I wish to preserve the following (as opposed to the preceding) duplicated substring of a comma-delimited string while removing the preceding duplicating substring.
1- Initial state of string before duplicate appended:
aaa,bbb,ccc,ddd,eee
2- bbb dynamically appended to string:
aaa,bbb,ccc,ddd,eee,bbb
3- Preceding bbb now must be removed:
aaa,ccc,ddd,eee,bbb
How can the following function, or any function for that matter, reproduce what I seek?
function unique(list) {
var result = [];
$.each(list, function(i, e) {
if ($.inArray(e, result) == -1) {
result.push(e);
}
});
return result;
}