Last change
on this file since 525 was
525,
checked in by hendrikvanantwerpen, 11 years ago
|
- Allow empty subcodes.
- Use HTTPResult exclusively on server (no more q).
- Set readonly & disabled on ourselves as well in _ComplexValueMixin
- Split server into several modules.
- Check codes on the variable level, not question level.
- We can add modules in design documents now.
|
File size:
916 bytes
|
Line | |
---|
1 | var _ = require('underscore') |
---|
2 | ; |
---|
3 | |
---|
4 | var exportFields = exports.collectFields = function collectFields(field,obj) { |
---|
5 | if ( _.isObject(obj) ) { |
---|
6 | return _.reduce(obj,function(vals,val,key){ |
---|
7 | if ( key === field ) { |
---|
8 | vals.push(val); |
---|
9 | } |
---|
10 | return vals.concat(collectFields(field,val)); |
---|
11 | },[]); |
---|
12 | } else { |
---|
13 | return []; |
---|
14 | } |
---|
15 | }; |
---|
16 | |
---|
17 | var findDuplicates = exports.findDuplicates = function(array,iterator) { |
---|
18 | iterator = iterator || _.identity; |
---|
19 | array = _.sortBy(array,iterator); |
---|
20 | return _.chain(_.initial(array)) |
---|
21 | .zip(_.rest(array)) |
---|
22 | .reduce(function(dups,nAndSn){ |
---|
23 | if ( iterator(nAndSn[0]) === iterator(nAndSn[1]) && |
---|
24 | nAndSn[0] !== _.last(dups) ) { |
---|
25 | return dups.concat([nAndSn[0]]); |
---|
26 | } |
---|
27 | return dups; |
---|
28 | },[]) |
---|
29 | .value(); |
---|
30 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.