result
to store the uncommented source code lines.in_block_comment
to False
to track whether we are inside a block comment.buffer
to temporarily store characters from the current line that are not part of a comment.source
array.
a. If not in a block comment, reset buffer
to an empty string.
b. Iterate over each character in the line.
i. If in a block comment, look for the end of the block comment (*/
).
ii. If not in a comment, look for the start of any comment (//
or /*
).
iii. If no comment is found, append the character to buffer
.
c. If the end of the line is reached and not in a block comment, append buffer
to result
if buffer
is not empty.result
list.