I have this function which get me only unique values in array:
function sort_unique(arr) {
var obj = {};
for (var i = 0; i < arr.length; i++) {
obj[arr[i]] = true;
}
arr = [];
for (var key in obj) {
arr.push(key);
}
return arr;
}
I need this function to show me repeatedly all uniques in array. Now when I use this in 'for' cycle with index and when all unique values is passed the function return 'undefined'.
Example:
Cat 1 Cat 2 undefined undefined undefined
I need to return:
Cat 1 Cat 2 Cat 1 Cat 2 Cat 1.... etc..
Can you re-work this for me ?
Thanks!