Created
March 22, 2019 19:20
-
-
Save snewcomer/43d7286f588b4d38ac37f25374ca1fc0 to your computer and use it in GitHub Desktop.
matching line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const removeMatchingLine = (str, match) => { | |
let index = str.indexOf(match); | |
// If it is not found, return str | |
if (index === -1) { | |
return str; | |
} | |
// Look for the previous line feed | |
let start = index; | |
while(str.charAt(start) !== "\n") { | |
start--; | |
} | |
start++; | |
// Look for next by line feed | |
let end = index + match.length + 1; | |
while(str.charAt(end) !== "\n") { | |
end++; | |
} | |
end++; | |
return str.substring(0, start) + str.substring(end); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment