Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17109
| From | Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Unique values of array |
| Date | 2012-11-09 18:43 +0000 |
| Organization | Home |
| Message-ID | <kU7v+sED7UnQFwmG@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <f874a1da-b06c-43af-beb6-fe05c5245469@p22g2000vby.googlegroups.com> |
In comp.lang.javascript message <f874a1da-b06c-43af-beb6-fe05c5245469@p2 2g2000vby.googlegroups.com>, Thu, 8 Nov 2012 05:00:51, Asen Bozhilov <asen.bozhilov@gmail.com> posted: >I have seen different approach to find the unique values in array. The answer depends on what you mean by "find". If the array A is ["a", "b", "a"] is the answer 2, the location of the (only) unique item, or is it "b", the value of the item? From the answer 2, one can rapidly discover "b" - but from the answer "b" another half-scan may on average be needed to obtain the 2. Create an empty Object, B. Scan through A, finding entries S = A[k]. For each, increment B[S], taking undefined as meaning zero. Then scan B; your value answers are the indexes of its elements with count==1. For position answers, instead increment B[S].count and, if B[S].Pos is undefined set it to k. The answers are now those B[S].Pos for which B[S].count == 1. Or something like that. -- (c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05. Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 05:00 -0800
Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-08 06:10 -0800
Re: Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 06:26 -0800
Re: Unique values of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-08 21:21 +0100
Re: Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 13:06 -0800
Re: Unique values of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-09 02:26 +0100
Re: Unique values of array Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> - 2012-11-09 18:43 +0000
Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-10 09:06 -0800
Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-10 20:19 +0100
Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-10 20:26 +0100
Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-11 08:47 -0800
Re: Unique values of array Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> - 2012-11-11 16:52 +0000
Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-12 05:10 -0800
Re: Unique values of array Dr J R Stockton <reply1246@merlyn.demon.co.uk.invalid> - 2012-11-13 16:39 +0000
Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-14 10:21 +0100
Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-14 04:32 -0800
csiph-web