Pot.Collection.unique

{Array|*} Pot.Collection.unique ({Array|*} object [, {Boolean} loose = false [, {Boolean} ignoreCase = false]])

Pot.js で利用可能。 PotLite.js では利用できません。

引数 object の要素をユニークにして返します。

引数 object の要素をユニークにした、新しい配列またはオブジェクトを生成し 返します。
引数 loose が 真 (true) として渡されると、比較は == で行われます。
デフォルトは false で === で比較します。
引数 ignoreCase が 真 (true) として渡されると、比較の際に大文字小文字を区別しません。
デフォルトは区別します。

Pot.globalize() が適応されている場合、Pot.unique() が unique() で実行できます。

object の要素をユニークにした要素を持つ、新しい配列またはオブジェクトを返します。

// ----- Array -----
debug(unique(
 [1, 2, 3, 4, 5, 3, 5, 'a', 3, 'b', 'a', 'c', 2, 5]
)); // [1, 2, 3, 4, 5, 'a', 'b', 'c']

debug(unique(
  [5, 7, 8, 3, 6, 1, 7, 2, 3, 8, 4, 2, 9, 5]
)); // [5, 7, 8, 3, 6, 1, 2, 4, 9]

debug(unique(
  ['1', 1, '2', 2, 0, '0', '', null, false, (void 0)],
  true
)); // ['1', '2', 0, null]

debug(unique(
  ['abc', 'ABC', 'Foo', 'bar', 'foO', 'BaR'],
  false, true
)); // ['abc', 'Foo', 'bar']

debug(unique(
  [1, 1, [123], (function(a) { return a;}),
   [123], {a: 5}, (function(a) { return a; }), {a: 5}]
)); // [1, [123], (function() { return a; }), {a: 5}]

// ----- Object -----
debug(unique(
  {a: 1, b: 2, c: 3, d: 1, e: 3, f: 2}
)); // {a: 1, b: 2, c: 3}

debug(unique(
  {foo: 1, bar: 2, FOo: 3, Bar: '1', baZ: '2'},
  true, true
)); // {foo: 1, bar: 2, FOo: 3}

debug(unique(
  {a: 1, b: 2, c: 3, d: '1', e: '3', f: 5},
  true
)); // {a: 1, b: 2, c: 3, f: 5}

// ----- String -----
debug(unique('abcABCabc-----foobarBaZ')); // 'abcABC-forZ'
debug(unique('abcABCabc-----foobarBaZ', true, true)); // 'abc-forZ'