forked from alibaba/nquery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistinct.js
49 lines (42 loc) · 1000 Bytes
/
distinct.js
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
43
44
45
46
47
48
49
// (C) 2011-2013 Alibaba Group Holding Limited.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation.
// Author :windyrobin <[email protected]>
/**
* @param {Object} dc like :{
* columns : ['col1', 'col2'],
* data : [
* ['a', 'b', 'c'],
* ['b', 'c', 'd']
* ]
* }
*/
module.exports = function (dc){
dc.data = distinct(dc.data);
return dc;
};
function distinct(data){
var res = [];
var map = {};
for(var i = 0; i < data.length; i++){
var cols = data[i];
var key = [];
for(var j = 0; j < cols.length; j++){
var c = cols[j];
key.push((typeof c ) + c);
}
key = key.join('_');
if(map[key] === undefined){
map[key] = true;
res.push(cols);
}
}
return res;
}
function debug(str){
//console.log(str);
}
function inspect(obj){
//console.log(require('util').inspect(obj));
}