UIZE JavaScript Framework

TO DO - Uize.Array.Dupes

This is a TO DO document for the Uize.Array.Dupes module.

1. Proposed New Methods

1.1. Uize.Array.Dupes.getDupes

Returns an array of dupe info objects.

1.2. Uize.Array.Dupes.getValueCount

Returns the number of occurrences of the specified value.

1.3. Uize.Array.Dupes.getValueCounts

Returns a lookup array of counts per value.

2. Support Loose Type Comparison

For the Uize.Array.Dupes.dedupe method, support canonicalizers that can achieve the effect of loose type comparison.

2.1. Canonicalize Primitive Type Values to Strings

One approach for a simple canonicalizer to perform loose type deduping would be to canonicalize primitive type values to strings, and map both null and undefined to a nully value object stand-in object...

var nullyValueStandin = {};
function (value) {
  return (
    Uize.isPrimitive (value)
      ? value + ''
      : Uize.isNully (value)
        ? nullyValueStandin
        : value

2.2. Equivalent Canonical Values

An alternative approach would allow a canonicalizer to return multiple equivalent canonical values...

when the canonicalizer sees a number value, it would return the number value, the string serialization of the number, and the boolean equivalent of the number
when the canonicalizer sees a boolean value, it would return the number equivalent of the boolean, and the string serialization of the boolean
when the canonicalizer sees the value null, it would return the value null, the value 0, and the value undefined

Problems with this approach are...

canonicalizers should be able to return array values, so how would a canonicalizer that is to return multiple values differentiate that intent from simply returning an array as a canonicalized result? Perhaps the canonicalizer would have to have a property on it to indicate that it uses this signature, so that the return value would not have to be overloaded.
if a canonicalizer could return multiple values, code that currently does the lookup and the insert would have to be wrapped in a loop to do multiple lookups and multiple inserts