From e129d1a85ce276879d9139da6bac524adb0d4804 Mon Sep 17 00:00:00 2001
From: Madhurima Chakraborty <56744323+MadhuNimmo@users.noreply.github.com>
Date: Fri, 2 Oct 2020 18:05:09 -0400
Subject: [PATCH 1/3] Added program to compute common leading and trailing
 substring

Calculates Longest common leading and trailing substring of two strings and returns both at the same time
---
 .../string/LongestCommLeadtrailSubString      | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 src/algorithms/string/LongestCommLeadtrailSubString

diff --git a/src/algorithms/string/LongestCommLeadtrailSubString b/src/algorithms/string/LongestCommLeadtrailSubString
new file mode 100644
index 00000000..25bc9ddb
--- /dev/null
+++ b/src/algorithms/string/LongestCommLeadtrailSubString
@@ -0,0 +1,42 @@
+/**
+ * Calculates Longest common leading and trailing substring of two strings
+ * @param  {Number} a First string
+ * @param  {Number} b Second string
+ * @return {Number}   Longest common leading/trailing substring
+ */
+const ltcs = (str1, str2) => {
+        var leading = "";
+        var trailing = "";
+        var leadflag = false;
+        var trailflag = false;
+        var end1 = str1.length - 1
+        var end2 = str2.length - 1
+
+        let pos = 0
+
+        while (pos <= end1 && pos <= end2 && (leadflag === false || trailflag === false)) {
+                //console.log(str1[pos], str2[pos])
+                if (leadflag === false) {
+                        if (str1[pos] === str2[pos]) {
+                                leading = str1.substring(0, pos+1)
+                                
+                        }
+                        else{
+                                leadflag = true
+                        }
+                }
+                if (trailflag === false) {
+                        if (str1[end1 - pos] === str2[end2 - pos]) {
+                                trailing = str1.substring(end1 - pos)
+                                
+                        }
+                        else{
+                                trailflag = true;
+                        }
+                }
+                pos++
+        }
+        return [leading, trailing]
+};
+
+module.exports = ltcs;

From 3067caf595c784fb08b8c9a97ecd50557bb41550 Mon Sep 17 00:00:00 2001
From: Madhurima Chakraborty <56744323+MadhuNimmo@users.noreply.github.com>
Date: Fri, 2 Oct 2020 18:24:25 -0400
Subject: [PATCH 2/3] Update .gitignore

To remove DS_Store files
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 2f0dd3cf..af679f82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 /.nyc_output
 /npm-debug.log
 dist
+**/.DS_Store

From 4ba061f3a6c1a2a9d40dfe3c436c0f9ba3900253 Mon Sep 17 00:00:00 2001
From: Madhurima Chakraborty <56744323+MadhuNimmo@users.noreply.github.com>
Date: Fri, 2 Oct 2020 20:13:13 -0400
Subject: [PATCH 3/3] Added LongestCommLeadtrailSubString.js

Added Program to compute Longest Common Leading or Trailing Substrings along with tests
---
 .DS_Store                                     | Bin 0 -> 8196 bytes
 package-lock.json                             |  56 +++++++++++++-----
 src/.DS_Store                                 | Bin 0 -> 6148 bytes
 src/algorithms/.DS_Store                      | Bin 0 -> 6148 bytes
 src/algorithms/string/.DS_Store               | Bin 0 -> 6148 bytes
 ...tring => LongestCommLeadtrailSubString.js} |  13 ++--
 test/.DS_Store                                | Bin 0 -> 6148 bytes
 test/algorithms/.DS_Store                     | Bin 0 -> 6148 bytes
 test/algorithms/string/testleadtrail.js       |  38 ++++++++++++
 9 files changed, 87 insertions(+), 20 deletions(-)
 create mode 100644 .DS_Store
 create mode 100644 src/.DS_Store
 create mode 100644 src/algorithms/.DS_Store
 create mode 100644 src/algorithms/string/.DS_Store
 rename src/algorithms/string/{LongestCommLeadtrailSubString => LongestCommLeadtrailSubString.js} (81%)
 create mode 100644 test/.DS_Store
 create mode 100644 test/algorithms/.DS_Store
 create mode 100644 test/algorithms/string/testleadtrail.js

diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..d4288847e65169c0a014ff49e9b8612644d625e8
GIT binary patch
diff --git a/package-lock.json b/package-lock.json
index af75e273..b64d1db0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -483,6 +483,7 @@
       "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
       "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=",
       "dev": true,
+      "optional": true,
       "requires": {
         "kind-of": "^3.0.2",
         "longest": "^1.0.1",
@@ -3854,7 +3855,8 @@
         "ansi-regex": {
           "version": "2.1.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "aproba": {
           "version": "1.2.0",
@@ -3875,12 +3877,14 @@
         "balanced-match": {
           "version": "1.0.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -3895,17 +3899,20 @@
         "code-point-at": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "concat-map": {
           "version": "0.0.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "console-control-strings": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -4022,7 +4029,8 @@
         "inherits": {
           "version": "2.0.3",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "ini": {
           "version": "1.3.5",
@@ -4034,6 +4042,7 @@
           "version": "1.0.0",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -4048,6 +4057,7 @@
           "version": "3.0.4",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
@@ -4055,12 +4065,14 @@
         "minimist": {
           "version": "0.0.8",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "minipass": {
           "version": "2.2.4",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.1",
             "yallist": "^3.0.0"
@@ -4079,6 +4091,7 @@
           "version": "0.5.1",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
@@ -4159,7 +4172,8 @@
         "number-is-nan": {
           "version": "1.0.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -4171,6 +4185,7 @@
           "version": "1.4.0",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "wrappy": "1"
           }
@@ -4256,7 +4271,8 @@
         "safe-buffer": {
           "version": "5.1.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "safer-buffer": {
           "version": "2.1.2",
@@ -4292,6 +4308,7 @@
           "version": "1.0.2",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
@@ -4311,6 +4328,7 @@
           "version": "3.0.1",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "ansi-regex": "^2.0.0"
           }
@@ -4354,12 +4372,14 @@
         "wrappy": {
           "version": "1.0.2",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "yallist": {
           "version": "3.0.2",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         }
       }
     },
@@ -5193,7 +5213,8 @@
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
       "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=",
-      "dev": true
+      "dev": true,
+      "optional": true
     },
     "loose-envify": {
       "version": "1.4.0",
@@ -5640,6 +5661,7 @@
           "version": "0.1.4",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "kind-of": "^3.0.2",
             "longest": "^1.0.1",
@@ -5961,7 +5983,8 @@
         "is-buffer": {
           "version": "1.1.6",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "is-builtin-module": {
           "version": "1.0.0",
@@ -6045,6 +6068,7 @@
           "version": "3.2.2",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "is-buffer": "^1.1.5"
           }
@@ -6091,7 +6115,8 @@
         "longest": {
           "version": "1.0.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "lru-cache": {
           "version": "4.1.3",
@@ -6357,7 +6382,8 @@
         "repeat-string": {
           "version": "1.6.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "require-directory": {
           "version": "2.1.1",
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..a3326275a2c612de6f15cf61358736aa99de6cab
GIT binary patch
diff --git a/src/algorithms/.DS_Store b/src/algorithms/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..7185f35591f31cbb368cb1bb0b76def581a5fa35
GIT binary patch
diff --git a/src/algorithms/string/.DS_Store b/src/algorithms/string/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..ad874d49ea1cf1f592eb59973d4eeee19ba96ff8
GIT binary patch
diff --git a/src/algorithms/string/LongestCommLeadtrailSubString b/src/algorithms/string/LongestCommLeadtrailSubString.js
similarity index 81%
rename from src/algorithms/string/LongestCommLeadtrailSubString
rename to src/algorithms/string/LongestCommLeadtrailSubString.js
index 25bc9ddb..1d17a36d 100644
--- a/src/algorithms/string/LongestCommLeadtrailSubString
+++ b/src/algorithms/string/LongestCommLeadtrailSubString.js
@@ -1,21 +1,24 @@
 /**
- * Calculates Longest common leading and trailing substring of two strings
+ * Calculates Longest common leading and trailing substring of two numbers
  * @param  {Number} a First string
  * @param  {Number} b Second string
  * @return {Number}   Longest common leading/trailing substring
  */
-const ltcs = (str1, str2) => {
+const LongestCommLeadtrailSubString = (str1, str2) => {
         var leading = "";
         var trailing = "";
         var leadflag = false;
         var trailflag = false;
+        if(str1.length ===0 || str2.length === 0){
+                console.log("Must enter valid strings")
+        }
+
         var end1 = str1.length - 1
         var end2 = str2.length - 1
 
         let pos = 0
 
         while (pos <= end1 && pos <= end2 && (leadflag === false || trailflag === false)) {
-                //console.log(str1[pos], str2[pos])
                 if (leadflag === false) {
                         if (str1[pos] === str2[pos]) {
                                 leading = str1.substring(0, pos+1)
@@ -36,7 +39,7 @@ const ltcs = (str1, str2) => {
                 }
                 pos++
         }
-        return [leading, trailing]
+        return {"leading":leading,"trailing": trailing}
 };
 
-module.exports = ltcs;
+module.exports = LongestCommLeadtrailSubString;
\ No newline at end of file
diff --git a/test/.DS_Store b/test/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..d9c3af285fef669ff67571333c7de662b65a0238
GIT binary patch
diff --git a/test/algorithms/.DS_Store b/test/algorithms/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..30b048b2c0dae7b46548df87b8f6632542740077
GIT binary patch
diff --git a/test/algorithms/string/testleadtrail.js b/test/algorithms/string/testleadtrail.js
new file mode 100644
index 00000000..47da7230
--- /dev/null
+++ b/test/algorithms/string/testleadtrail.js
@@ -0,0 +1,38 @@
+/* eslint-env mocha */
+const LongestCommLeadtrailSubString = require('../../../src/algorithms/string/LongestCommLeadtrailSubString');
+const expect = require('expect');
+
+
+describe('Longest common leading and trailing substring of two strings', () => {
+  it('should return empty strings if the inputs mismatch entirely', () => {
+    const stringA = 'ABCDEF';
+    const stringB = 'QRST';
+
+    const SubStrings = LongestCommLeadtrailSubString(stringA, stringB);
+    expect(SubStrings).toStrictEqual({"leading":"","trailing": ""});
+  });
+
+  it('should return only trailing common substring if no leading common subtring found', () => {
+    const stringA = 'ABCMNOP';
+    const stringB = 'EFGHMNOP';
+
+    const SubStrings = LongestCommLeadtrailSubString(stringA, stringB);
+    expect(SubStrings).toStrictEqual({"leading":"","trailing": "MNOP"});
+  });
+
+  it('should return only leading common substring if no trailing common subtring found', () => {
+    const stringA = 'ABCMNOP';
+    const stringB = 'ABCYZ';
+
+    const SubStrings = LongestCommLeadtrailSubString(stringA, stringB);
+    expect(SubStrings).toStrictEqual({"leading":"ABC","trailing": ""});
+  });
+
+  it('should return both leading common substring and trailing common subtring if found', () => {
+    const stringA = 'ABCYEFG';
+    const stringB = 'ABCZEFG';
+
+    const SubStrings = LongestCommLeadtrailSubString(stringA, stringB);
+    expect(SubStrings).toStrictEqual({"leading":"ABC","trailing": "EFG"});
+  });
+});
