TUI.unique
=
function
( array ) {
var
ret
=
[], record
=
{}, it, tmp;
var
type
=
{
“number”:
function
(n){
return
“_TUI_num”
+
n; },
“string”:
function
(n){
return
n; },
“
boolean
”:
function
(n){
return
“_TUI_boolean”
+
n; },
“object”:
function
(n){
return
n
===
null
?
“TUI_null” : $.data(n); },
“undefined”:
function
(n){
return
“_TUI_undefined”; }
};
for
(
var
i
=
0
, length
=
array.length; i
<
length; i
++
) {
it
=
tmp
=
array[i];
tmp
=
type[
typeof
it](it);
if
(
!
record[tmp] ) {
ret.push(it);
record[tmp]
=
true
;
}
}
return
ret;
};
测试:
var
b
=
[
1
,
3
,
5
];
TUI.unique([
1
,
3
,
4
,
5
,
null
,
false
,$(
"
.pack
"
)[
0
],b,
"
ab
"
,
"
cc
"
,[
1
,
3
],
3
,
6
,b,
1
,
false
,
null
,
"
null
"
,
""
,
"
false
"
,
""
,$(
"
.pack
"
)[
0
],
"
cc
"
])