please tell me any good algorithm/code to get list of unique values from array and count of its occurrence in array. (i am using javascript).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a method that will strip the duplicates from an array and returns a new array with the unique values, you may want to check the following Array.unique implementation. With an O(n2) complexity, it is certainly not the quickest algorithm, but will do the job for small unsorted arrays.
It is licensed under GPLv3, so I should be allowed to paste the implementation here:
You would be able to use it as follows:
You may want to tweak the above to somehow append the number of occurrences of each value.