From 86574e861651186af75656717c5ddf5bc4e74f8d Mon Sep 17 00:00:00 2001
From: Manuel Friedli <manuel@fritteli.ch>
Date: Thu, 6 Sep 2018 14:45:21 +0200
Subject: [PATCH] Make code shorter.

---
 src/app/converter-registry.service.ts | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts
index d84733b..85e6304 100644
--- a/src/app/converter-registry.service.ts
+++ b/src/app/converter-registry.service.ts
@@ -36,12 +36,7 @@ export class ConverterRegistryService {
   }
 
   public getConverter(id: string): Converter {
-    for (let i = 0; i < this.converters.length; i++) {
-      if (this.converters[i].getId() === id) {
-        return this.converters[i];
-      }
-    }
-    return undefined;
+    return this.converters.find((converter: Converter): boolean => converter.getId() === id);
   }
 
   private init(): void {
@@ -67,11 +62,11 @@ export class ConverterRegistryService {
   }
 
   private registerConverter(converter: Converter): void {
-    this.converters.forEach((c: Converter) => {
-      if (c.getId() === converter.getId()) {
-        throw new Error('Converter-ID ' + converter.getId() + ' is already registered!');
-      }
-    });
+    // Don't allow duplicate registration of the same converter id
+    if (this.converters.some((c: Converter): boolean => c.getId() === converter.getId())) {
+      throw new Error(`Converter-ID ${converter.getId()} is already registered!`);
+    }
+
     this.converters.push(converter);
   }
 }