Skip to content

Commit

Permalink
reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed Jun 20, 2018
1 parent d43b143 commit fa2017e
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions gedbrowserng-frontend/src/app/utils/api-comparators.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { ApiSource, ApiPerson, ApiSubmitter } from '../models';

export class ApiComparators {
comparePersons(a: ApiPerson, b: ApiPerson) {
const val = a.indexName.localeCompare(b.indexName);
if (val !== 0) {
return val;
}
return a.string.localeCompare(b.string);
comparePersons = (a: ApiPerson, b: ApiPerson) => {
return this.compare(a.indexName, a.string, b.indexName, b.string);
}

compareSources(a: ApiSource, b: ApiSource) {
const val = a.title.localeCompare(b.title);
if (val !== 0) {
return val;
}
return a.string.localeCompare(b.string);
compareSources = (a: ApiSource, b: ApiSource) => {
return this.compare(a.title, a.string, b.title, b.string);
}

compareSubmitters = (a: ApiSubmitter, b: ApiSubmitter) => {
return this.compare(a.name, a.string, b.name, b.string);
}

compareSubmitters(a: ApiSubmitter, b: ApiSubmitter) {
const val = a.name.localeCompare(b.name);
compare = (a1: string, a2: string, b1: string, b2: string) => {
const val = a1.localeCompare(b1);
if (val !== 0) {
return val;
}
return a.string.localeCompare(b.string);
return a2.localeCompare(b2);
}
}

0 comments on commit fa2017e

Please sign in to comment.