0

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!

2
Contributors
3
Replies
44
Views
1 Year
Discussion Span
Last Post by agajvery
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.