Browse Source

Use lodash intersection method

pull/292/head
Julian Simioni 9 years ago
parent
commit
7b9d61c5ec
  1. 14
      helper/type_mapping.js
  2. 14
      helper/types.js

14
helper/type_mapping.js

@ -1,4 +1,5 @@
var extend = require('extend');
var extend = require('extend'),
_ = require('lodash');
var TYPE_TO_SOURCE = {
'geoname': 'gn',
@ -69,17 +70,8 @@ var TYPES = Object.keys(TYPE_TO_SOURCE);
var SOURCES = Object.keys(SOURCE_TO_TYPE);
var LAYERS = Object.keys(LAYER_TO_TYPE);
/**
* Calculate the set-style intersection of two arrays
*/
var intersection = function intersection(set1, set2) {
return set2.filter(function(value) {
return set1.indexOf(value) !== -1;
});
};
var sourceAndLayerToType = function sourceAndLayerToType(source, layer) {
return intersection(SOURCE_TO_TYPE[source], LAYER_WITH_ALIASES_TO_TYPE[layer]);
return _.intersection(SOURCE_TO_TYPE[source], LAYER_WITH_ALIASES_TO_TYPE[layer]);
};
module.exports = {

14
helper/types.js

@ -1,13 +1,5 @@
var type_mapping = require( '../helper/type_mapping' );
/**
* Calculate the set-style intersection of two arrays
*/
var intersection = function intersection(set1, set2) {
return set2.filter(function(value) {
return set1.indexOf(value) !== -1;
});
};
var _ = require('lodash');
/**
* Combine all types and determine the unique subset
@ -27,11 +19,11 @@ module.exports = function calculate_types(clean_types) {
var types = type_mapping.types;
if (clean_types.from_layers) {
types = intersection(types, clean_types.from_layers);
types = _.intersection(types, clean_types.from_layers);
}
if (clean_types.from_sources) {
types = intersection(types, clean_types.from_sources);
types = _.intersection(types, clean_types.from_sources);
}
return types;

Loading…
Cancel
Save