Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17212

Re: Unique values of array

From Dr J R Stockton <reply1246@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: Unique values of array
Date 2012-11-13 16:39 +0000
Organization Home
Message-ID <P3HV2TEOfnoQFwoI@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <f874a1da-b06c-43af-beb6-fe05c5245469@p22g2000vby.googlegroups.com> <kU7v+sED7UnQFwmG@invalid.uk.co.demon.merlyn.invalid> <f3044be9-979c-448d-94c6-b85acd8ac102@r7g2000vbo.googlegroups.com> <kN1$Y7G4e9nQFwXN@invalid.uk.co.demon.merlyn.invalid> <7cc060dd-9e63-4442-9b34-98294e8ed1ba@o8g2000yqh.googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <7cc060dd-9e63-4442-9b34-98294e8ed1ba@o8
g2000yqh.googlegroups.com>, Mon, 12 Nov 2012 05:10:13, Scott Sauyet
<scott.sauyet@gmail.com> posted:

>Dr J R Stockton wrote:
>> Scott Sauyet posted:
>>> Dr J R Stockton wrote:
>>>> Asen Bozhilov 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?
>>
>>> The performance test link Asen supplied [1] makes it clear that what
>>> he's looking for is, in this case, ["a", "b"], although quite possibly
>>> the order of the resulting array wouldn't matter.  In other words,
>>> he's not looking for the values which appear only once in the input
>>> but rather one copy of each (possibly multiply occurring) value in the
>>> input.
>>
>> The same approach works for that.  Fill the new object as before, and
>> read out all of its elements.  I fill objects in that fashion in my
>> <http://www.merlyn.demon.co.uk/linxchek.htm>, frequently used, and read
>> them in various ways, including   for (X in Object) { ... }.
>
>But that will work only if the elements of the array are Strings or
>Numbers.  The OP was looking for a technique that would work for
>arbitrary types.

It should be possible to convert objects of arbitrary types to strings
which are identical if and only if the objects are identical.  And I
think you mean Strings xor Numbers!

But in that case one needs to consider the meaning of identical.

  W = function(A) { return A*A }
  X = function(A) { return A*A }
  Y = function(B) { return B*B }
  Z = function(B) { return B*B}

AIUI, W X Y Z are all unequal in value.  But the functions are all
essentially the same.

-- 
 (c) John Stockton, nr London UK               Reply address via Home Page.
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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