If the line contains no line comment, null should be returned.
cutComment('let foo; // bar') should return 'bar', but its returning 'let foo; // bar'.
function cutComment(comment) {
if (comment === null) {
return null;
} else {
return comment.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '').trim();
}
}
console.log(cutComment('let foo; // bar'));
changed the regex to match anything that comes after //
function cutComment(comment) {
if(!comment) return null
let match = comment.match(/(?<=\/\/).+/)
if(match.length > 0 ) {
return match[0]
}else{
return null
}
}
console.log(cutComment('let foo; // bar'));