Skip to content

Commit 8f2999c

Browse files
committed
fix bug and include more test cases
1 parent 6ff0dbb commit 8f2999c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

LeetCode/ImportPath/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ module.exports = importPath = (str1, str2) => {
4343
if (str1Splited.length === 1) {
4444
finalLocation = "./";
4545
} else {
46-
finalLocation = `${finalLocation}../`;
46+
for (let i = 0; i < str1Splited.length - 1; i++) {
47+
finalLocation = `${finalLocation}../`;
48+
}
4749
}
4850

4951
for (let i = 0; i < str2Splited.length - 1; i++) {
@@ -55,4 +57,4 @@ module.exports = importPath = (str1, str2) => {
5557
return finalLocation;
5658
};
5759

58-
console.log(importPath("src/route/app/home.js", "src/route/utils/helpers.js"));
60+
console.log(importPath("src/route/app/home.js", "src/utils/helpers.js"));

LeetCode/ImportPath/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ describe("tets for import path problem", () => {
88
"src/route/utils/helpers.js"
99
);
1010
expect(actual).toEqual(expected);
11+
12+
expected = "../../utils/helpers.js";
13+
actual = importPath("src/route/app/home.js", "src/utils/helpers.js");
14+
expect(actual).toEqual(expected);
1115
});
1216
});

0 commit comments

Comments
 (0)