Skip to content

Commit 17c69e0

Browse files
authored
Merge pull request #43 from csivitu/dev
fix: Use trimEnd instead of trim
2 parents 907b43d + 08ea860 commit 17c69e0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-executor",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "A CLI/library to execute code against test cases in various languages and obtain relevant results.",
55
"main": "dist/src/index.js",
66
"keywords": [

src/utils/matchLines.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
export default function matchLines(expected: string, obtained: string): 'Pass' | 'Fail' {
22
function splitAndTrim(code: string) {
3-
return code.split('\n').map((sentence) => sentence.trim());
3+
return code.split('\n').map((sentence) => sentence.trimEnd());
44
}
55

6-
const expectedArray = splitAndTrim(expected);
7-
const obtainedArray = splitAndTrim(obtained);
6+
const expectedArray = splitAndTrim(expected.trim());
7+
const obtainedArray = splitAndTrim(obtained.trim());
88

9-
const minLength = Math.min(expectedArray.length, obtainedArray.length);
9+
if (expectedArray.length !== obtainedArray.length) {
10+
return 'Fail';
11+
}
12+
13+
const { length } = expectedArray;
1014

11-
for (let i = 0; i < minLength; i += 1) {
15+
for (let i = 0; i < length; i += 1) {
1216
if (expectedArray[i] !== obtainedArray[i]) {
1317
return 'Fail';
1418
}

0 commit comments

Comments
 (0)