Skip to content

Commit 533884c

Browse files
committed
Simplify logic
1 parent cebaf80 commit 533884c

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

helper/diffPlaces.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,29 +188,28 @@ function isAddressDifferent(item1, item2){
188188
}
189189

190190
function isGeonamesConcordanceSame(item1, item2) {
191-
let wof_record;
192-
let gn_record;
193-
194-
if (item1.source === 'geonames' && item2.source === 'whosonfirst') {
195-
gn_record = item1;
196-
wof_record = item2;
197-
} else if (item2.source === 'geonames' && item1.source === 'whosonfirst') {
198-
gn_record = item2;
199-
wof_record = item1;
200-
} else {
201-
// could not match to one geonames and one wof concordance, so this check does not apply
191+
const items = [item1, item2];
192+
193+
const wof_record = items.find(i => i.source === 'whosonfirst');
194+
const gn_record = items.find(i => i.source === 'geonames');
195+
196+
// must have found one wof and one gn record or this check does not apply
197+
if (!wof_record || !gn_record) { return false; }
198+
199+
const concordances = _.get(wof_record, 'addendum.concordances');
200+
201+
if (!concordances) {
202202
return false;
203203
}
204204

205-
const concordances = _.get(wof_record, 'addendum.concordances');
205+
const json = codec.decode(concordances);
206+
const concordance_id = json['gn:id'];
206207

207-
if (concordances) {
208-
const json = codec.decode(concordances);
209-
const concordance_id = json['gn:id'];
208+
if (!concordance_id || !_.isNumber(concordance_id)) { return false; }
210209

211-
if (concordance_id && typeof concordance_id === 'number' && concordance_id.toString() === gn_record.source_id) {
212-
return true;
213-
}
210+
// only records with a matching concordance pass this check
211+
if (concordance_id.toString() === gn_record.source_id) {
212+
return true;
214213
}
215214

216215
return false;

0 commit comments

Comments
 (0)