Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pick first result

  • Loading branch information...
commit 41575385b49ed52d008cb347c344ea00b26c71c2 1 parent cf5b857
@mshafrir authored
Showing with 13 additions and 9 deletions.
  1. +7 −5 lib/cusip.js
  2. +6 −4 src/cusip.coffee
View
12 lib/cusip.js
@@ -21,11 +21,13 @@
return (new cusip_source(cusip_code, parallel_callback)).fetch();
};
}), function(err, results) {
- if (err != null) {
- return console.log('err', err);
- } else {
- return console.log('results', results);
- }
+ var compacted, cusip_data, is_found;
+ compacted = _.compact(_.flatten(results));
+ is_found = !_.isEmpty(compacted);
+ cusip_data = _.extend({
+ code: cusip_code
+ }, _.isEmpty(compacted) ? {} : _.first(compacted));
+ return console.log('cusip_data', cusip_data);
});
}).call(this);
View
10 src/cusip.coffee
@@ -17,7 +17,9 @@ async.parallel _.map(cusip_sources, (cusip_source) ->
(new cusip_source(cusip_code, parallel_callback)).fetch()
),
(err, results) ->
- if err?
- console.log 'err', err
- else
- console.log 'results', results
+ compacted = _.compact(_.flatten(results))
+ is_found = not _.isEmpty(compacted)
+ cusip_data = _.extend {code: cusip_code},
+ if _.isEmpty(compacted) then {} else _.first compacted
+ console.log 'cusip_data', cusip_data
+ #mainCallback(null, if is_found then cusip_data else null)
Please sign in to comment.
Something went wrong with that request. Please try again.