Conversation
Fix expected output: change 'with' to 'wIth' in sed exercise instructions
|
Thanks for opening a new PR! AI started to review it |
| if (showNumbers) { | ||
| console.log(`${counterLines++} ${line}`); | ||
| } else if (showNonBlankNumbers) { | ||
| // increment and show numbers only if the line is not empty. | ||
| if (line.trim() !== "") { | ||
| console.log(`${counterLines++} ${line}`); | ||
| } else { | ||
| // print empty lines | ||
| console.log(line); | ||
| } | ||
| } else { | ||
| console.log(line); | ||
| } |
There was a problem hiding this comment.
I've noticed that the logic for printing lines with or without numbers is repeated in a few places inside your forEach loop. If you ever wanted to change how lines are printed, you'd have to update it in multiple spots. Can you think of a way to group this logic into a function, so you only have to update it in one place if you want to change how lines are displayed?
|
|
||
| //filter the - from the array argv as it's a flag. | ||
| const filePaths = argv.filter((arg) => !arg.startsWith("-")); | ||
| let counterLines = 1; |
There was a problem hiding this comment.
The variable 'counterLines' is declared outside your main file loop and is used for numbering lines across all files. Do you want the line numbers to continue across files, or should they reset for each file? If you want them to reset, where could you declare 'counterLines' so it starts from 1 for each file?
| const lines = content.split("\n").length - 1; | ||
| const words = content | ||
| .trim() | ||
| .split(/\s+/) | ||
| .filter((word) => word != "").length; | ||
| // here I used Buffer.byteLength even if characters and bytes can be the same number .length, however sometimes an emoji or special characters can be heavier 2b or 4b | ||
| const bytes = Buffer.byteLength(content); | ||
| const characters = content.length; |
There was a problem hiding this comment.
The logic for counting lines, words, bytes, and characters is written inside the forEach loop. If you wanted to use this logic elsewhere, you might have to copy it. Can you think of a way to move this logic into a function that takes the file content and returns these counts?
There was a problem hiding this comment.
This seems quite speculative again?
No description provided.