---
# System prepended metadata

title: Strip Comments

---

Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out.

Example:

Given an input string of:

apples, pears # and bananas
grapes
bananas !apples
The output expected would be:

apples, pears
grapes
bananas
The code would be called like so:

var result = solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"])

result should == "apples, pears\ngrapes\nbananas"

---

I need to find a solution with deleting all the text that follows any of the passed comment markers and includes any spaces at the end of the line
    
---
Send to me link to questions:

How to split a string using multiple delimiter characters in JavaScript?

How to remove comments from a string using markers in JavaScript?

How does the map method work in JavaScript arrays?

How to use the reduce method to process an array in JavaScript?

---
```
function solution(input, markers) {
  return input
    .split('\n')
    .map(line => markers.reduce((acc, marker) => acc.split(marker)[0].trim(), line))
    .join('\n');
}
```