Add tags

Add tags to the following comment
うーん。プリミティブ値だけの配列だったらこれでいける。
でも、オブジェクトとかが入ってくると 
toString() の結果によっては正しい結果にならないなあ。

alert([1, 2, 3, 3, 2, 1].uniq()); // [1, 2, 3]
1
2
3
4
5
6
7
Array.prototype.uniq = function () {
  for (var i = 0, r = [], s = {}; i < this.length; i++) {
    if (!s[this[i]]) r.push(this[i]);
    s[this[i]] = true;
  }
  return r;
};

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...