Files: d99d85a16533a82af15af59ea09e68058f746596 / 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