This comment is reply for 463 id:amachang: Object Type にも対応した書き...(アレイのuniq). Go to thread root.
匿名 #530(2007/07/11 05:11 GMT) [ JavaScript ] Rating0/0=0.00
いっそ両方とも実装してみるとか。ダメ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
Array.prototype.uniq = function(usedObjKey) { if (typeof(usedObjKey) == 'undefined') usedObjKey = (typeof(this[0]) == 'object'); var ret = []; if (usedObjKey) { for (var i=0, len=this.length, s=[]; i<len; i++) { if (s.indexOf(this[i]) < 0) { ret.push(this[i]); s.push(this[i]); } } } else { for (var i=0, len=this.length, s={}; i<len; i++) { if (!s[this[i]]) ret.push(this[i]); s[this[i]] = true; } } return ret; } /** * @site http://developer.mozilla.org/ja/docs/ * Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from<len; from++) if (from in this && this[from] === elt) return from; return -1; }; }
Rating0/0=0.00-0+
[ reply ]
匿名
#530()
[
JavaScript
]
Rating0/0=0.00
Rating0/0=0.00-0+