1
var removeComments = function (source) {3
let multi_line_comment = false;6
source.forEach((line) => {7
for (let idx = 0; idx < line.length; ++idx) {8
// if /* is not ongoing, check for start of a comment or not9
if (!multi_line_comment) {10
// if comment is //, ignore the rest of the line11
if (line[idx] + line[idx + 1] === "//") {14
// if comment if /*, set multi-line flag and move to next index15
else if (line[idx] + line[idx + 1] === "/*") {16
multi_line_comment = true;19
// if not a comment start, add to string to be added to result24
// if /* comment is ongoing26
// if closing comment */ is encountered, set multi-line flag off and move to next index27
if (line[idx] + line[idx + 1] === "*/") {28
multi_line_comment = false;33
// if /* comment is not ongoing and str is not empty, add to result as one code line34
if (str.length && !multi_line_comment) {36
str = ""; //reset the str