Files: 8c0347d8e7f88171cd4c45eec22b42c5c7332fac / throughs / unique.js
428 bytesRaw
1 | |
2 | |
3 | function id (e) { return e } |
4 | var prop = require('../util/prop') |
5 | var filter = require('./filter') |
6 | |
7 | //drop items you have already seen. |
8 | module.exports = function unique (field, invert) { |
9 | field = prop(field) || id |
10 | var seen = {} |
11 | return filter(function (data) { |
12 | var key = field(data) |
13 | if(seen[key]) return !!invert //false, by default |
14 | else seen[key] = true |
15 | return !invert //true by default |
16 | }) |
17 | } |
18 | |
19 |
Built with git-ssb-web